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 – Date.prototype.format():
    Sometimes you write code that you wish you could totally rework. That is how I feel about jPaq’s Date.prototype.format(). The real issue I have with it is that the metacharacters are not intuitive. Therefore, I decided to write a new version of this
  2. JavaScript – Add Commas To Numbers:
    At times, I have had to add commas to numbers in order to make them look better in different applications. Even though there isn’t a native way to do this in JavaScript, the code can be quite short, sweet and to the point: function addCommas(intNum)
  3. JavaScript Snippet – Parse A Spreadsheet Address:
    Today I am starting work on a quick flashcard app that will use Google Docs to read data from a spreadsheet. I thought I had written and published a function which parses an Excel like cell address and converts it into the column number and the row number
  4. JScript Example - Calculating 2^4194304:
    See how you can attempt to calculate an extremely large number with JScript.
  5. JavaScript – Get Window Size:
    At times you may want to get the size of the window. I don’t remember where I came across the original code, but I modified it and created the following function: function getWindowSize() { var doc = document, body = doc.body, docElem = doc.document
  6. JavaScript – Loading External JS Files:
    If you need a way to load external JavaScript files sequentially with JavaScript, you can use the following function: /** * Loads one more external JS files and optionally calls a callback function * when done. * @param {!Array.<string>} urls * UR
  7. JavaScript Snippet – getAbsPathFor():
    Mission & Code Sometimes you just need a way of determining the absolute path from a specified relative path. When you are in this situation, you may use the following code: (function() { var img = new Image(); getAbsPathFor = function(relativePath) {
  8. Wrapping Integers In JavaScript & PostgreSQL:
    Recently, I had to create a PostgreSQL equivalent of the Java hashCode() function. In order to do this, I needed a way to make sure that numbers that exceed the INTEGER representation (ranging from -2^31 to 2^31-1) will be wrapped. In JavaScript, this is
  9. JavaScript Snippet – Undo Camel Case:
    Probably due to it being so late, I was looking for code to uncamelize (undo camel-casing) any string. I came across what claimed to be a solution in PHP but unfortunately did nothing but lowercased my string. Therefore I decided to write my own solution:
  10. JavaScript – Date.now():
    One of the newer functions that was added as of the 5th edition of ECMA-262 is Date.now(). This function returns the number of milliseconds that have passed since January 1, 1970 at midnight GMT time (UTC). If you desire to write code that uses this newer