Overview
This jQuery plugin aims to replace the basic functionality provided by the standard JavaScript alert(), confirm(), and prompt() functions. What’s the benefit of using custom methods? Well, a few good reasons, really.
- These are completely customizable via CSS (which can make your apps
look much more professional) - You can set a custom title for each dialog
- IE7 users get an ugly warning and usually have to reload the page if
you use a regular prompt()
These methods simulate a true modal dialog box. They will automatically reposition themselves if you resize the browser window (unlike many existing dialog/lightbox-style plugins). If you include the jQuery UI Draggable plugin, the dialogs can be moved by dragging their title bars. Everything you need to produce the dialogs in the demonstration is included in the download.
Update: this plugin has been archived and is no longer actively maintained. We recommend jQuery UI’s dialog widget for similar functionality.
Usage
This plugin utilizes the $.alerts namespace, but there are
three built-in shortcut functions that make implementation easier:
- jAlert(message, [title, callback])
- jConfirm(message, [title, callback])
- jPrompt(message, [value, title, callback])
Unlike their native JavaScript counterparts, you can use HTML in the message parameter. To specify a newline, you can use either \n or <br />. These methods do not return the same values as confirm() and prompt(). You must
access the resulting values using a callback function. (See the demo for more details.)
Screenshot
Demo & Download
This plugin is dual-licensed under the GNU General Public License and the MIT License and is copyright 2008 A Beautiful Site, LLC.
