The Windows shell goes wild. An
ActiveXObject assigned to the
WScript.Shell object, provides access to some very useful core os components indeed. ActiveXObjects are notoriously shy and eluding, they prefer to operate in the background and their actions may not always be immediately seen, such as when reading local files, but the
method is unmistakable and unavoidable.
Use this to display customized alert-type dialogs, with ‘Yes’ and ‘No’ buttons, and a variety of icons. There is even the option to have the dialog window time out automatically and disappear without user action, and resume script from there.
Description : Displays a modeless dialog, with features
returnvalue = obj.Popup( text, timeout, title, features );
|The button clicked by the user's reply.||Number||n/a||-1|
|The shell object.||Object||Required||n/a|
|The number of seconds after which the popup self-closes.||Number||Optional||
|The text in the title bar.||String||Optional||
|Specification of buttons and icon.||Number||Optional||
A modal window is one that blocks user interaction with the originating window until it is dismissed, such in contrast to modeless dialogs that do not prevent scrolling and text selections in the main window. Other windows, even if running the same application, remain normally accessible.
Ordinary alert and confirm boxes accept Unicode escaped characters (like
alert( '\u20ac for euro' ) ) within the message text generally, but the character set in popups from the shell seems more limited. Experiments suggest entering symbols directly gives the best chance of the characters displaying correctly in the popup window. A test is undertaken below.
timeout period should be taken with a great margin for inaccuracy. If omitted or
0 (zero), it can wait forever.
features have no distinct effect on the type of return value, to the end user the type of the dialog window is a very important aspect of the communication. To differentiate between types, there is a choice of a six groups of buttons, and four icons. The values for both, as listed in the appendix below, are simply added together and the resulting number is passed as the argument. Each icon is usually associated with a sound clip on the local machine to finish off the experience.
No further customization is possible.
There are four types of iconography available. The illustrations displayed below have been shot in Windows ME.
The function runs on submission of the form, which passes itself as the parameter. First it assembles the code as specified by the user, and writes it to the output area. Next the shell is called into being (stored in variable
o), and it is immediately put to use by calling its
Popup() method on line 9.
The value to use for the buttons is read directly from the
selectedIndex property of the
<select> element. This is possible because the button values form a neat zero based range. The value for the icon must be taken from the
value attribute of the selected
<option>, which is converted to an integer with the extra
+ before adding the two up on line 6.
The user replies and the returnvalue (variable
p) is tossed in a
switch statement, with branches for each of possible buttons clicked. They should be able to speak for themselves. (A version which uses an
if/else construction to the same effect can be found near the bottom of this page's source.) More useful actions then these example messages and a
return statement to another function are, well, thinkable.
As we are using
ActiveXObjects, we have limited ourselves to a sure ie only audience, and can safely employ the non-standard quick and dirty shortcut
innerHTML property of a fieldset to contain the resulting code, highlighted by a function called
hilitejs. Finally, the calls to function
show how the object
o can be passed to other scopes than the one in which it was created, and so behave just like other variables.
Now what sequence of buttons would lead to the secret message of line 31? Look carefully. No, it isn't a trick question, but perhaps just a bit of danse macabre.
One of the possible values for the buttons and one for the icons may be added together as the
features parameter of the
Popup() method. If either is left out, default zero values apply. According to the Microsoft documentation, these lists are not complete, but the rest has yet to be found. According to experiments on Windows ME and XP, passing a value of 6 or 12 for the buttons makes the popup return
0 before it pops up; 7, 9 and 11 all show a dialog with no buttons (and no reaction to either Return or Esc, the dialog is dismissed by trying to close the main window); 8 gives a regular ‘OK’ and ‘Cancel’ set. When a value of 10 is specified, the dialog features ‘OK’ and ‘Cancel’ buttons, and a mysterious ‘Survey’ button...
|2||Abort, Ignore, Retry|
|3||Yes, No, Cancel|
|-1||None (timed out)|