JScript - Modified Alert Box
HomeJScriptJXtension
Main Menu Home HTA JavaScript PHP Examples Million Digit Number Free Samples Disable Excel Menus Display Random Facts Drive Information Emulate Lock Keys Enable Excel Menus Hoax Virus Message Includables jPaq Modified Alert Box toVBArray() Outer Links MSDN Reference JScript Reference

Now Available In jPaq!!!

Now this function is available in the custom JScript library, jPaq.  The nice thing about jPaq is that everything is documented and the library that you download is specifically tailored to your needs. Click here to create your own free jPaq today!

Purpose:

Give the scripter the ability to use the alert(...) function in any stand-alone JScript file.

Download:

You can find this helpful 424 byte script here.

Parameters:

alert(message [, title [, options [, duration]]])

description The message that appears in the alert box.
title Optional. The title of the alert box. By default, this value is the file name of the script.
options Optional. The button type and icon type you would like to appear in the alert box. By default, this value is set to alert.Exclamation + alert.OKOnly.
duration Optional. The duration in seconds that the alert box will appear before ending and returning alert.Timeout. If none is specified, the alert box will never timeout.

Returns:

If a timeout occurs, alert.Timeout is returned. If a timeout doesn't occur, the response constant associated with the button pressed will be returned.

Constants:

Example Code:

NOTE: All of these examples presuppose that the code from ModifiedAlertBox.js is encountered first.

The following code will display a typical alert box, almost identical to the one displayed when clicking here:

alert("Hello world!!!");

The following code will display an alert box with a message of "Where in the world is Carmen Sandiego?" and a title of "Carmen Sandiego":

alert("Where in the world is Carmen Sandiego?", "Carmen Sandiego");

The following code will display an alert box with a message of "I am the computer which means I am always right.", a title of "Computer Rules", and the Information icon:

alert("I am the computer which means I am always right.", "Computer Rules", alert.Information);

The following code will display an alert box with a message of "Is your PC slow?", a title of "PC Speed", the Question icon, and the "Yes" and "No" buttons. After the user picks one of the buttons, he or she will be informed of which button was chosen:

if(alert("Is your PC slow?", "PC Speed", alert.YesNo + alert.Information) == alert.Yes)
	alert("I see that you believe your PC is slow.  I really wish I could help.",
		"Slow PC", alert.Information);
else
	alert("I am glad to hear that you don't think your PC is slow.",
		"PC Isn't Slow", alert.Information);

The following code will display an alert box with a message of "Your PC couldn't download the Internet.", a title of "Download Unsucessful", the Exclamation icon, and the "Retry" and "Cancel" buttons. If the user waits more than five seconds, the alert box will time out and a new message will be displayed. If the user doesn't let the alert box timeout, an appropriate message will displayed, making it obvious which button was clicked:

switch(alert("Your PC couldn't download the Internet.", "Download Unsucessful",
	alert.RetryCancel + alert.Exclamation, 5))
{
	case alert.Retry:
		alert("Sorry, but I think that it would be a waste of both your time and my"
			+ " time if I try to download the Internet.", "Can't Retry Download",
			alert.Critical);
		break;
	case alert.Cancel:
		alert("Good choice, there is no reason to have all of the junk on the web"
			+ " anyway.", "Cancel Download", alert.Information);
		break;
	case alert.Timeout:
		alert("I guess you don't care what happens.", "Timeout Occurred");
}

Related Search Results

  1. JavaScript - GET Object Emulation:
    Learn how to emulate the GET object with JavaScript.
  2. JavaScript Snippet - getAbsPathFor(...):
    Get the absolute path from a given relative path.
  3. Wormbites 2008 (Desktop Version):
    The ultimate Snake game with multiple brain-teasing levels. You can also custom design you own levels.
  4. JXtension - A Small, Yet Powerful JavaScript Library:
    JXtension is a small, yet powerful JavaScript library.
  5. JavaScript - Dynamic Interaction:
    Learn how to handle events with plain JavaScript.