jQuery Alert Dialogs (Alert, Confirm, & Prompt Replacements)
Written by Cory S.N. LaViska on December 29th, 2008
A set of methods that provide an inline, customizable way to show JavaScript alerts, confirmations, and prompts.
Contents
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 re-position 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.
Requires jQuery 1.2.6 or above.
Implementation
Include the following in the <head> section of your HTML document(s):
<script src="/path/to/jquery.js" type="text/javascript"></script>
<script src="/path/to/jquery.ui.draggable.js" type="text/javascript"></script>
<!-- Core files -->
<script src="/path/to/jquery.alerts.js" type="text/javascript"></script>
<link href="/path/to/jquery.alerts.css" rel="stylesheet" type="text/css" media="screen" />
Make sure you update the path to the respective files. If you are already using the jQuery UI Draggable plugin (including the UI core), simply omit the link to jquery.ui.draggable.js.
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.)
Compatibility
This plugin requires jQuery 1.2.6 or above and has been tested to work in the following browsers:
- Internet Explorer 6 & 7
- Firefox 2 & 3
- Safari 3
- Chrome
- Opera 9
Demo
Visit the live demonstration page to see examples of each dialog.
Download
Download the current version of this plugin: Version 1.1
This plugin is provided to you as-is, at absolutely no cost. If you would like to support its development, feel free to contribute any amount you prefer via PayPal. As always, you are welcome to contribute code for bug fixes and feature enhancements as well. Either way, thanks for supporting our efforts!
Known Issues
- ENTER and ESC keys (to accept/cancel) don’t work in WebKit browsers
- The draggable plugin doesn’t currently work in Opera
- IE6 acts a bit differently as position: fixed isn’t supported.
Licensing
This plugin is dual-licensed under the GNU General Public License and the MIT License and is copyright 2008 A Beautiful Site, LLC.













Comments
— xcdesz on Dec 30th, 2008
— Paul on Dec 30th, 2008
— Richard Garbutt on Dec 30th, 2008
— Richard Garbutt on Dec 30th, 2008
— Cory S.N. LaViska on Dec 30th, 2008
— Tian on Dec 31st, 2008
— Cory S.N. LaViska on Dec 31st, 2008
— ingenium on Dec 31st, 2008
— Suhas Dhoke on Jan 1st, 2009
— Josh on Jan 1st, 2009
— Cory S.N. LaViska on Jan 1st, 2009
— Josh on Jan 1st, 2009
— Tom on Jan 3rd, 2009
— Cory S.N. LaViska on Jan 3rd, 2009
— Tom on Jan 3rd, 2009
— Cory S.N. LaViska on Jan 3rd, 2009
— Tom on Jan 3rd, 2009
— Elijah Grey on Jan 4th, 2009
— Elijah Grey on Jan 4th, 2009
— Sachin on Jan 5th, 2009
— var on Jan 7th, 2009
— Kevin on Jan 12th, 2009
— DotnetShadow on Jan 14th, 2009
— Spencer on Jan 14th, 2009
— Cory S.N. LaViska on Jan 14th, 2009
— Spencer on Jan 14th, 2009
— Thiago on Jan 16th, 2009
— Thiago on Jan 16th, 2009
— david on Jan 18th, 2009
— david on Jan 19th, 2009
— David on Jan 19th, 2009
— David on Jan 19th, 2009
— Kevin on Jan 21st, 2009
— Matt on Jan 22nd, 2009
— Matt on Jan 22nd, 2009
— John on Jan 22nd, 2009
— Sandeep on Jan 23rd, 2009
— BScottA on Jan 23rd, 2009
— Cory LaViska on Jan 23rd, 2009
— Jean on Jan 23rd, 2009
— Damian on Jan 26th, 2009
— Cory S.N. LaViska on Jan 26th, 2009
— kyrael on Jan 28th, 2009
— jkojs on Jan 28th, 2009
— Sergei on Jan 29th, 2009
— Nibbi on Jan 30th, 2009
— Rose on Feb 2nd, 2009
— Rose on Feb 2nd, 2009
— Rose on Feb 3rd, 2009
— Rose on Feb 3rd, 2009
— GillouX on Feb 5th, 2009
— DiemVuong on Feb 6th, 2009
— العاب on Feb 8th, 2009
— George on Feb 9th, 2009
— jkojs on Feb 9th, 2009
— Lorenzo on Feb 10th, 2009
— jkojs on Feb 11th, 2009
— smgolden on Feb 12th, 2009
— Cory S.N. LaViska on Feb 12th, 2009
— hessam on Feb 13th, 2009
— David on Feb 13th, 2009
— smgolden on Feb 13th, 2009
— Cory S.N. LaViska on Feb 14th, 2009
— smgolden on Feb 14th, 2009
— Cory S.N. LaViska on Feb 14th, 2009
— smgolden on Feb 14th, 2009
— Wouke on Feb 17th, 2009
— carolbac on Feb 17th, 2009
— niju on Feb 18th, 2009
— carolbac on Feb 20th, 2009
— redscreen on Feb 24th, 2009
— hellward on Feb 28th, 2009
— ashorlivs on Mar 4th, 2009
— ashorlivs on Mar 4th, 2009
— ashorlivs on Mar 4th, 2009
— Steven on Mar 6th, 2009
— Eric on Mar 8th, 2009
— Cory S.N. LaViska on Mar 8th, 2009
— Nick on Mar 10th, 2009
— Cory S.N. LaViska on Mar 10th, 2009
— Nick on Mar 10th, 2009
— Ilya Kantor on Mar 11th, 2009
— Keith on Mar 11th, 2009
— Arnaud on Mar 11th, 2009
— anushka on Mar 12th, 2009
— krishnan on Mar 13th, 2009
— Eric on Mar 13th, 2009
— Matt on Mar 23rd, 2009
— Eric on Mar 23rd, 2009
— Matt on Mar 24th, 2009
— Steve on Mar 24th, 2009
— Juan Machado on Mar 24th, 2009
— dth on Mar 25th, 2009
— Cory S.N. LaViska on Mar 25th, 2009
— Ben Y. on Mar 28th, 2009
— David P on Mar 31st, 2009
— msegmx on Apr 1st, 2009
— Cory S.N. LaViska on Apr 1st, 2009
— msegmx on Apr 1st, 2009
— strizzi on Apr 2nd, 2009
— Cory S.N. LaViska on Apr 2nd, 2009
— strizzi on Apr 6th, 2009
— Bill on Apr 6th, 2009
— Cory S.N. LaViska on Apr 6th, 2009
— pp_coda on Apr 8th, 2009
— Lars Nielsen Lind on Apr 11th, 2009
— Lars Nielsen Lind on Apr 11th, 2009
— Tamonash on Apr 12th, 2009
— Sujith on Apr 15th, 2009
— Jean-François on Apr 16th, 2009
— rhalf on Apr 20th, 2009
— Timo on Apr 22nd, 2009
— Euan Green on Apr 30th, 2009
— Bowman on May 1st, 2009
— Cory S.N. LaViska on May 1st, 2009
— Atso Peter on May 6th, 2009
— Celestino on May 7th, 2009
— Sthrudel on May 13th, 2009
— Phil on May 14th, 2009
— small on May 14th, 2009
— Cory S.N. LaViska on May 14th, 2009
— BillL on May 15th, 2009
— Richard Pack on May 20th, 2009
— Justine on May 25th, 2009
— Nancy on May 29th, 2009
— Robin on May 29th, 2009
— Alessandro Marinuzzi on Jun 1st, 2009
— David on Jun 13th, 2009
— Nazwan on Jun 23rd, 2009
— heohni on Jun 30th, 2009