JavaScript Customizable Alert

I have developed a JavaScript alert box to replace the horrible default alert box from JavaScript. It has been created to work much like you would create an alert box in many windows application languages.

Basically it's completely customizable. When you call the function to show an alert box you just pass in the variables to specify it's contents and it's styled in css in a clean and simple way. Here is a break down of the variables you pass to the alert box;

  1. The first is the event from which the alert was called.
  2. Next pass it a string for the title of the alert box.
  3. This one is the actual message displayed in the alert.
  4. If you want the message to have an icon pass in the file path to one here, or leave blank.
  5. Pass in an array of button values here ie ["OK","Cancel"]
  6. Here you must pass in an equal length array of functions for the onclick events of the buttons above.
  7. Specify the width of the alert box, all text will wrap at this width.
  8. Finally here you pass in the file path to an icon for the top right corner exit icon.

Click here to see an example or download the source.

You can style the box in any way you want by editing the CSS.


Tested to work in the following browsers;

  • IE 7
  • FireFox 2.0.0.2
  • Opera 9.02


Last Updated : 10 March 2007