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. JScript – File & Folder Chomper:
    I use to always work on Windows and at times it seemed that certain files just didn’t want to go to the recycling bin. For that reason I would always write a JScript which had the following code: (new ActiveXObject("Scripting.FileSystemObject
  2. JavaScript – Define If Undefined:
    There have been many times when I needed a way to define a function (or variable) only if it wasn’t already defined. Since this seems to be such a common situation, I decided to write a function which will only define a variable, in a given namespac
  3. JavaScript – Polling:
    At times you may need to use a polling function in order to wait for an event before the rest of your code can fire. One way we can solve this is with a polling function: /** * @license JS Polling - By Chris West - MIT License */ (function(emptyObj, empty
  4. JavaScript – outerHTML:
    One DOM element property that has been provided in Internet Explorer that isn’t natively available in some other browsers is outerHTML. Fortunately there is a cross-browser solution for getting this property: (function() { /** * Gets the HTML of the
  5. Escape & Unescape – Deprecated?:
    Two of the most widely used JavaScript functions that are now deprecated are the escape() and unescape() functions. This means that in order to ensure that your code will continue to work in all future browsers, you should use one of the alternative funct
  6. Deep Copy of Arrays:
    With jPaq and many other JavaScript libraries, it is very easy to do a shallow copy of an array. On the other hand, it isn’t as easy to do a deep copy of arrays. For this reason, I plan on replacing the Array.prototype.clone() function with the foll
  7. POW Answer – JavaScript Self Inequality:
    As two people indicated in their comments in the original POW post, the answer is NaN. You can even do the following to check it: alert(NaN === NaN); // outputs false Weird stuff, right?!?!?!
  8. JavaScript – Primitives & Objects:
    Purpose of the valueOf() Function Let me start off by explaining the commonly misunderstood valueOf() function. The purpose of this function is to return a primitive which represents the specified object. Why is this necessary? Let’s use the followi
  9. JavaScript Box:
    A simple way to test out JavaScript. Test out your functions and objects. Do some advanced tests with JXtension.
  10. JavaScript – Parsing A Number:
    If you should ever need to parse a number into an array of bits or a different base you can use the following function: var splitNumber = (function(MAX) {   for (; MAX + 1 - MAX == 1; MAX *= 2){}   return function (num, radix) {