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 – Set Default Function Parameter Values:
    It has been a while since I wrote a JavaScript utility function so a few minutes ago, I had the idea to create a function which will allow you to set the default value of a parameter for any given function. After writing the following function, I thought
  2. JavaScript – Heron’s Square Root Algorithm:
    One of the first things that many people learn in an introduction to Computer Sciences course is the algorithm for calculating the square root of a number. The algorithm, which is often attributed to Heron of Alexandria, is as follows: Formulate a guess.
  3. JavaScript – Date Difference Function:
    A few months ago I wrote a blog post about extensions to the Date.prototype. That post provided ways to add date parts and subtract date parts. Today’s post shows you how to use a generic Date.prototype.diff() function to find the difference between
  4. JavaScript – Yet A Better typeOf() Function:
    I am currently working on an updated version of Wormbites.  In the process, I wanted to use my typeOf() function that I posted here. The only thing is, I thought it would be even better if the function would optionally take two parameters, in which c
  5. JavaScript – For Each Object Property:
    Iterating through the key-value pairs of an object that one has created is a task often executed. In view of this, I wrote the following code as a quick and easy way to iterate through all of the keys using a callback function: (function(hasOwnProperty, u
  6. JavaScript – Indenting Text:
    One thing I needed to do recently was indent a series of strings with a variable number of tabs or spaces. Thusly, I decided to create the following function which can be used by anyone that would need such a function: /** * Indents the given string * @pa
  7. IE7 JavaScript Instruction Limit:
    Have you ever wondered why so many people hate Microsoft? For instance, people are always talking badly about the workarounds that you have to do in order to make things work in Internet Explorer. For me, when first starting developing web pages, all I kn
  8. Camel Case In JavaScript:
    Almost a month ago, I posted about creating a camel case function in VBScript. Now I think it is time to see a simple way to implement this function in JavaScript: String.prototype.toCamelCase = function(cap1st) { return ((cap1st ? "-" : ""
  9. 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
  10. JavaScript – Date.prototype Extensions:
    Yesterday’s post made me want to extend the Date.prototype object a bit more. Therefore I came up with the following code: // Date.prototype Extensions - By Chris West - MIT Licensed (function() { var arr = "Years|FullYear Months|Month