jQuery Alert Dialogs (Alert, Confirm, & Prompt Replacements)

A note from A Beautiful Site’s founder: We developed Surreal to be easy for you and your clients. If you’re a web designer, you should take a look at the simple, hosted CMS that’s changing the way content is managed. Surreal integrates in moments and is trusted by over 18,000 websites. Try it out for free and let us know what you think! Visit Website »

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.

Demo | Download the latest version

If you enjoyed this article, please share it with a friend!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>