taint(dataElementName)
Use taint to mark data that otherwise is not tainted.
In some cases, control flow rather than data flow carries tainted information. In these cases, taint is added to the script's window. You can add taint to the script's window by calling taint with no arguments. See "Tainting that results from conditional statements".
taint does not modify its argument; instead, it returns a marked copy of the value, or, for objects, an unmarked reference to the value.
taintedStatus=taint(window.defaultStatus) // taintedStatus now cannot be sent in a URL or form post without // the end user's permission
navigator.taintEnabled()
Use taintEnabled to determine if data tainting is enabled. taintEnabled returns true if data tainting is enabled, false otherwise. The user enables or disables data tainting by using the environment variable NS_ENABLE_TAINT.
if (navigator.taintEnabled()) {
function1()
}
else function2()
Math.tan(number)
function getTan(x) {
return Math.tan(x)
}
If you pass getTan the
value Math.PI/4, it returns 0.9999999999999999.
1. formName.target 2. links[index].target 3. areaName.target
index is an integer representing a Link object or the name of a Link object as specified by the NAME attribute.
areaName is the value of the NAME attribute of an Area object.
You can set target using a string, if the string represents a window name. The target property cannot be assigned the value of a JavaScript expression or variable.
You can set the target property at any time.
document.musicInfo.target="msgWindow"
<INPUT TYPE="text" NAME="textName" VALUE="textValue" SIZE=integer [onBlur="handlerText"] [onChange="handlerText"] [onFocus="handlerText"] [onSelect="handlerText"]>
VALUE="textValue" specifies the initial value of the Text object. You can access this value using the defaultValue property.
SIZE=integer specifies the number of characters the Text object can accommodate without scrolling.
1. textName.propertyName 2. textName.methodName(parameters) 3. formName.elements[index].propertyName 4. formName.elements[index].methodName(parameters)
formName is either the value of the NAME attribute of a Form object or an element in the forms array.
index is an integer representing a Text object on a form or the name of a Text object as specified by the NAME attribute.
propertyName is one of the properties listed below.
methodName is one of the methods listed below.
A Text object is a form element and must be defined within a <FORM> tag.
Text objects can be updated (redrawn) dynamically by setting the value property (this.value).
If a form contains only one element, a Text object, then when the user enters a value and presses Return, the form submits. (This is a standard HTML feature.)
| Property | Description |
|---|---|
| defaultValue | Reflects the VALUE attribute |
| form property | Specifies the form containing the Text object |
| name | Reflects the NAME attribute |
| type | Reflects the TYPE attribute |
| value | Reflects the current value of the Text object's field |
|
|
|
<B>Last name:</B> <INPUT TYPE="text" NAME="last_name" VALUE="" SIZE=25>Example 2. The following example creates two Text objects on a form. Each object has a default value. The city object has an onFocus event handler that selects all the text in the field when the user tabs to that field. The state object has an onChange event handler that forces the value to uppercase.
<FORM NAME="form1"> <BR><B>City: </B><INPUT TYPE="text" NAME="city" VALUE="Anchorage" SIZE="20" onFocus="this.select()"> <B>State: </B><INPUT TYPE="text" NAME="state" VALUE="AK" SIZE="2" onChange="this.value=this.value.toUpperCase()"> </FORM>See also the examples for the onBlur, onChange, onFocus, and onSelect event handlers.
1. selectName.options[index].text 2. optionName.text
index is an integer representing an option in a Select object.
optionName is the name of a Select object option created using the Option() constructor.
You can set the text property at any time and the text displayed by the option in the Select object changes.
function getChoice() {
for (var i = 0; i < document.musicForm.musicType.length; i++) {
if (document.musicForm.musicType.options[i].selected == true) {
return document.musicForm.musicType.options[i].text
}
}
return null
}
The previous example assumes
that the Select object is similar to the following:
<SELECT NAME="musicType"> <OPTION SELECTED> R&B <OPTION> Jazz <OPTION> Blues <OPTION> New Age </SELECT>
<TEXTAREA NAME="textareaName" ROWS="integer" COLS="integer" [onBlur="handlerText"] [onChange="handlerText"] [onFocus="handlerText"] [onSelect="handlerText"]> textToDisplay </TEXTAREA>
ROWS="integer" and COLS="integer" define the physical size of the displayed input field in numbers of characters.
textToDisplay specifies the initial value of the Textarea object. A Textarea allows only ASCII text, and new lines are respected. You can access this value using the defaultValue property.
1. textareaName.propertyName 2. textareaName.methodName(parameters) 3. formName.elements[index].propertyName 4. formName.elements[index].methodName(parameters)
formName is either the value of the NAME attribute of a Form object or an element in the forms array.
index is an integer representing a Textarea object on a form or the name of a Textarea object as specified by the NAME attribute.
propertyName is one of the properties listed below.
methodName is one of the methods listed below.
A Textarea object is a form element and must be defined within a <FORM> tag.
Textarea objects can be updated (redrawn) dynamically by setting the value property (this.value).
To begin a new line in a Textarea object, you can use a newline character. Although this character varies from platform to platform (Unix is \n, Windows is \r, and Macintosh is \n), JavaScript checks for all newline characters before setting a string-valued property and translates them as needed for the user's platform. You could also enter a newline character programmatically--one way is to test the appVersion property to determine the current platform, then set the newline character accordingly. See the appVersion property for an example.
| Property | Description |
|---|---|
| defaultValue | Reflects the VALUE attribute |
| form property | Specifies the form containing the Textarea object |
| name | Reflects the NAME attribute |
| type | Specifies that the object is a Textarea object |
| value | Reflects the current value of the Textarea object |
|
|
|
<B>Description:</B> <BR><TEXTAREA NAME="item_description" ROWS=6 COLS=55> Our storage ottoman provides an attractive way to store lots of CDs and videos--and it's versatile enough to store other things as well. It can hold up to 72 CDs under the lid and 20 videos in the drawer below. </TEXTAREA>Example 2. The following example creates a string variable containing newline two characters for different platforms. When the user clicks the button, the Textarea object is populated with the value from the string variable. The result is three lines of text in the Textarea object.
<SCRIPT> myString="This is line one.\nThis is line two.\rThis is line three." </SCRIPT> <FORM NAME="form1"> <INPUT TYPE="button" Value="Populate the textarea" onClick="document.form1.textarea1.value=myString"> <P> <TEXTAREA NAME="textarea1" ROWS=6 COLS=55></TEXTAREA>See also the examples for the onBlur, onChange, onFocus, and onSelect event handlers.
document.title
title is a read-only property.
var newWindow = window.open("http://home.netscape.com")
var docTitle = newWindow.document.title
dateObjectName.toGMTString()
today.toGMTString()In this example, the toGMTString method converts the date to GMT (UTC) using the operating system's time-zone offset and returns a string value that is similar to the following form. The exact format depends on the platform.
Mon, 18 Dec 1995 17:28:35 GMT
dateObjectName.toLocaleString()
today.toLocaleString()In this example, toLocaleString returns a string value that is similar to the following form. The exact format depends on the platform.
12/18/95 17:28:35
stringName.toLowerCase()
var upperText="ALPHABET" document.write(upperText.toLowerCase())
1. top.propertyName 2. top.methodName 3. top.frameName 4. top.frames[index]
methodName is any method associated with the window object.
frameName and frames[index] are ways to refer to frames.
The top property is read-only. The value of the top property is
<object objectReference>where objectReference is an internal reference.
The statement top.length specifies the number of frames contained within the top-most ancestor window. When the top-most ancestor is defined as follows, top.length returns three:
<FRAMESET COLS="30%,40%,30%"> <FRAME SRC=child1.htm NAME="childFrame1"> <FRAME SRC=child2.htm NAME="childFrame2"> <FRAME SRC=child3.htm NAME="childFrame3"> </FRAMESET>The following example sets the background color of a frame called myFrame to red. myFrame is a child of the top-most ancestor window.
top.myFrame.document.bgColor="red"
objectName.toString() numberObjectName.toString([radix])
numberObjectName is the Number object to convert to a string.
radix is an integer between 2 and 16 specifying the base to use for representing numeric values.
document.write(theDog)
document.write("The dog is " + theDog)
You can use toString
within your own code to convert an object into a string, and you can create
your own function to be called in place of the default toString
method.
<IMG NAME="sealife" SRC="images\seaotter.gif" ALIGN="left" VSPACE="10">
Suppose you have an object type Dog and you want to create a toString method for it. The following code defines the Dog object type and creates theDog, an object of type Dog:
function Dog(name,breed,color,sex) {
this.name=name
this.breed=breed
this.color=color
this.sex=sex
}
theDog = new Dog("Gabby","Lab","chocolate","girl")
The following code creates objectToString,
the function that will be used in place of the default toString
method. This function generates a string containing each property, of the
form "property = value;".
function objectToString() {
var ret = "Object " + this.name + " is ["
for (var prop in this)
ret += " " + prop + " is " + this[prop] + ";"
return ret + "]"
}
The following code assigns the
user-defined function to the object's toString method:
Dog.prototype.toString = objectToStringWith the preceding code in place, any time theDog is used in a string context, JavaScript automatically calls the objectToString function, which returns the following string:
Object Gabby is [ name is Gabby; breed is Lab; color is chocolate; sex is girl; toString is function objectToString() { var ret = "Object " + this.name + " is ["; for (var prop in this) { ret += " " + prop + " is " + this[prop] + ";"; } return ret + "]"; } ;]
An object's toString method is usually invoked by JavaScript, but you can invoke it yourself as follows:
alert(theDog.toString())
var monthNames = new Array("Jan","Feb","Mar","Apr")
document.write("monthNames.toString() is " + monthNames.toString())
The output is as follows:
monthNames.toString() is Jan,Feb,Mar,Apr
flag = new Boolean(true)
document.write("flag.toString() is " + flag.toString() + "<BR>")
For example, suppose you create the function Dog shown in "User-defined toString methods". Any time Dog is used in a string context, JavaScript automatically calls the toString function, which returns the following string:
function Dog(name, breed, color, sex) { this.name = name; this.breed = breed; this.color = color; this.sex = sex; }
// The next two lines are valid
var howMany=10
document.write("howMany.toString() is " + howMany.toString() + "<BR>")
// The next line causes an error
document.write("45.toString() is " + 45.toString() + "<BR>")
document.write("location.toString() is " + location.toString() + "<BR>")
The output is as follows:
file:///C|/TEMP/myprog.htmlExample 2: Object with no string value. Suppose the following Image object named "sealife" exists:
<IMG NAME="sealife" SRC="images\seaotter.gif" ALIGN="left" VSPACE="10">Because the Image object itself has no string equivalent, sealife.toString() will return the following:
[object Image]Example 3: The radix parameter. The following example prints the string equivalents of the numbers 0 through 9 in decimal and binary.
for (x = 0; x < 10; x++) {
document.write("Decimal: ", x.toString(10), " Binary: ",
x.toString(2), "<BR>")
}
The preceding example produces
the following output:
Decimal: 0 Binary: 0 Decimal: 1 Binary: 1 Decimal: 2 Binary: 10 Decimal: 3 Binary: 11 Decimal: 4 Binary: 100 Decimal: 5 Binary: 101 Decimal: 6 Binary: 110 Decimal: 7 Binary: 111 Decimal: 8 Binary: 1000 Decimal: 9 Binary: 1001
stringName.toUpperCase()
var lowerText="alphabet" document.write(lowerText.toUpperCase())
1. objectName.type 2. navigator.mimeTypes[index].type
index is either an integer representing a MIME type supported by the client or a string containing the type of a MimeType object (from the type property).
For form elements, the value of the type property is assigned as follows:
for (var i = 0; i < document.form1.elements.length; i++) {
document.writeln("<BR>type is " + document.form1.elements[i].type)
}
See also the examples for the
MimeType object.
unescape("string")
unescape("%26")
The following example returns
"!#":
unescape("%21%23")
untaint(dataElementName)
Use untaint to clear tainting that marks data that should not to be sent by other scripts to different servers.
A script can untaint only data that originated in that script (that is, only data that has the script's taint code or has the identity (null) taint code). If you use untaint with a data element from another server's script (or any data that you cannot untaint), untaint returns the data without change or error.
In some cases, control flow rather than data flow carries tainted information. In these cases, taint is added to the script's window. You can remove taint from the script's window by calling untaint with no arguments, if the window contains taint only from the current window. See "Tainting that results from conditional statements".
untaint does not modify its argument; instead, it returns an unmarked copy of the value, or, for objects, an unmarked reference to the value.
untaintedStatus=untaint(window.defaultStatus) // untaintedStatus can now be sent in a URL or form post by other // scripts
document.URL
document.write("The current URL is " + document.URL)
navigator.userAgent
userAgent is a read-only property.
document.write("The value of navigator.userAgent is " +
navigator.userAgent)
For Navigator 2.0, this displays
the following:
The value of navigator.userAgent is Mozilla/2.0 (Win16; I)
Date.UTC(year, month, day [, hrs] [, min] [, sec])
month is a month between zero and 11.
date is a day of the month between one and 31.
hrs is hours between zero and 23.
min is minutes between zero and 59.
sec is seconds between zero and 59.
Because UTC is a static method of Date, you always use it as Date.UTC(), rather than as a method of a Date object you created.
gmtDate = new Date(Date.UTC(96, 11, 1, 0, 0, 0))
1. objectName.value 2. radioName[index].value 3. selectName.options.[index].value 4. fileUploadName.value 5. optionName.value
radioName is the value of the NAME attribute of a Radio object.
selectName is either the value of the NAME attribute of a Select object or an element in the elements array.
index is an integer representing a radio button in a Radio object or an option in a Select object.
fileUploadName is either the value of the NAME attribute of a FileUpload object or an element in the elements array.
optionName is the name of a Select object option created using the Option() constructor.
When a VALUE attribute is
not specified in HTML, the value property differs for each object:
value is a read-only property.
Do not confuse the value property with the name property. The name property is not displayed on-screen; it is used to reference the objects programmatically.
You can set the value property at any time.
Do not confuse the value property with the selection state of the object or the text that is displayed next to each checkbox and radio button. The checked property determines the selection state of the object, and the defaultChecked property determines the default selection state. The text that is displayed is specified following the <INPUT TYPE="checkbox"> or the <INPUT TYPE="radio"> tag.
value is a read-only property.
You can set the value property at any time. The display of the Text and Textarea objects updates immediately when you set the value property.
If you programmatically set the value property and then evaluate it, JavaScript returns the current value. If a user interactively modifies the value in the password field, you cannot evaluate it accurately unless data tainting is enabled. See "Using data tainting for security".
You can set the value property at any time.
You can set the value property at any time.
Do not confuse the value property with the selection state of the Select object or the text that is displayed as an option. The selected and selectedIndex properties determine which options are selected, and the defaultSelected property determines the default selection state. The text that is displayed in each option is specified by its text property.
function valueGetter() {
var msgWindow=window.open("")
msgWindow.document.write("submitButton.value is " +
document.valueTest.submitButton.value + "<BR>")
msgWindow.document.write("resetButton.value is " +
document.valueTest.resetButton.value + "<BR>")
msgWindow.document.write("helpButton.value is " +
document.valueTest.helpButton.value + "<BR>")
msgWindow.document.close()
}
This example displays the following
values:
Query Submit Reset HelpThe previous example assumes the buttons have been defined as follows:
<INPUT TYPE="submit" NAME="submitButton"> <INPUT TYPE="reset" NAME="resetButton"> <INPUT TYPE="button" NAME="helpButton" VALUE="Help">The following function evaluates the value property of a group of radio buttons and displays it in the msgWindow window:
function valueGetter() {
var msgWindow=window.open("")
for (var i = 0; i < document.valueTest.radioObj.length; i++) {
msgWindow.document.write
("The value of radioObj[" + i + "] is " +
document.valueTest.radioObj[i].value +"<BR>")
}
msgWindow.document.close()
}
This example displays the following
values:
on on on onThe previous example assumes the buttons have been defined as follows:
<BR><INPUT TYPE="radio" NAME="radioObj">R&B <BR><INPUT TYPE="radio" NAME="radioObj" CHECKED>Soul <BR><INPUT TYPE="radio" NAME="radioObj">Rock and Roll <BR><INPUT TYPE="radio" NAME="radioObj">Blues
objectName.valueOf()
You can use valueOf within your own code to convert an object into a primitive value, and you can create your own function to be called in place of the default valueOf method.
You rarely need to invoke the valueOf method yourself. JavaScript automatically invokes it when encountering an object where a primitive value is expected.
The valueOf method is most useful for the following object types. Most other objects have no primitive value.
Suppose you have an object type myNumberType and you want to create a valueOf method for it. The following code assigns a user-defined function to the object's valueOf method:
myNumberType.prototype.valueOf = new Function(functionText)With the preceding code in place, any time an object of type myNumberType is used in a context where it is to be represented as a primitive value, JavaScript automatically calls the function defined in the preceding code.
An object's valueOf method is usually invoked by JavaScript, but you can invoke it yourself as follows:
myNumber.valueOf()
document.vlinkColor
If you express the color as a hexadecimal RGB triplet, you must use the format rrggbb. For example, the hexadecimal RGB values for salmon are red=FA, green=80, and blue=72, so the RGB triplet for salmon is "FA8072."
document.vlinkColor="aqua"The following example sets the color of active links to aqua using a hexadecimal triplet:
document.vlinkColor="00FFFF"
imageName.vspace
vspace is a read-only property.
imageName.width
width is a read-only property.
windowVar = window.open("URL", "windowName" [,"windowFeatures"])
For details on defining a window,
see the open (window object) method.
To use a window object's properties and methods:
1. window.propertyName 2. window.methodName(parameters) 3. self.propertyName 4. self.methodName(parameters) 5. top.propertyName 6. top.methodName(parameters) 7. parent.propertyName 8. parent.methodName(parameters) 9. windowVar.propertyName 10. windowVar.methodName(parameters) 11. propertyName 12. methodName(parameters)To define an event handler for a window object, use the <BODY> or <FRAMESET> tags:
<BODY ... [onBlur="handlerText"] [onFocus="handlerText"] [onLoad="handlerText"] [onUnload="handlerText"]> </BODY> <FRAMESET ROWS="rowHeightList" COLS="columnWidthList" [onBlur="handlerText"] [onFocus="handlerText"] [onLoad="handlerText"] [onUnload="handlerText"]> [<FRAME SRC="URL" NAME="frameName">] </FRAMESET>
Note
On some platforms, placing an onBlur or onFocus event handler in a <FRAMESET> tag has no effect. Please see the release notes (after starting Netscape, choose Release Notes from the Help menu).For information on the <BODY> and <FRAMESET> tags, see the document and Frame objects.
To define an onError event handler for a window object:
window.onerror=errorHandlerFor information on specifying the onError event handler, see onError event handler.
windowName is the window name to use in the TARGET attribute of a <FORM> or <A> tag.
propertyName is one of the properties listed below.
methodName is one of the methods listed below.
errorHandler is the keyword null, the name of an error-handling function, or a variable or property that contains null or a valid function reference.
The self and window properties are synonyms for the current window, and you can optionally use them to refer to the current window. For example, you can close the current window by calling either window.close() or self.close(). You can use these properties to make your code more readable or to disambiguate the property reference self.status from a form called status. See the properties and methods listed below for more examples.
The top and parent properties are also synonyms that can be used in place of the window name. top refers to the top-most Navigator window, and parent refers to a window containing a frameset. See the top and parent properties.
Because the existence of the current window is assumed, you do not have to reference the name of the window when you call its methods and assign its properties. For example, status="Jump to a new location" is a valid property assignment, and close() is a valid method call. However, when you open or close a window within an event handler, you must specify window.open() or window.close() instead of simply using open() or close(). Due to the scoping of static objects in JavaScript, a call to close() without specifying an object name is equivalent to document.close().
When you reference the location object within an event handler, you must specify window.location instead of simply using location. Due to the scoping of static objects in JavaScript, a call to location without specifying an object name is equivalent to document.location, which is a synonym for document.URL.
You can reference a window's Frame objects in your code by using the frames array. The frames array contains an entry for each frame in a window with a <FRAMESET> tag.
Windows lack event handlers until some HTML is loaded into them containing a <BODY> or <FRAMESET> tag.
| Property | Description |
|---|---|
| closed | Specifies whether a window has been closed |
| defaultStatus | Reflects the default message displayed in the window's status bar |
| frames | An array reflecting all the frames in a window |
| length | Reflects the number of frames in a parent window |
| name | Reflects the windowName argument |
| opener | Specifies the window name of the calling document when a window is opened using the open method |
| parent | A synonym for the windowName argument and refers to a window containing a frameset |
| self | A synonym for the windowName argument and refers to the current window |
| status | Specifies a priority or transient message in the window's status bar |
| top | A synonym for the windowName argument and refers to the top-most Navigator window |
| window property | A synonym for the windowName argument and refers to the current window |
The following objects are
also properties of the window object:
|
|
|
win1.html, which defines the frames for the first window, contains the following code:
<HTML>
<HEAD>
<TITLE>Window object example: Window 1</TITLE>
</HEAD>
<BODY BGCOLOR="antiquewhite">
<SCRIPT>
window2=open("win2.html","secondWindow",
"scrollbars=yes,width=250, height=400")
document.writeln("<B>The first window has no name: "
+ window.name + "</B>")
document.writeln("<BR><B>The second window is named: "
+ window2.name + "</B>")
</SCRIPT>
<FORM NAME="form1">
<P><INPUT TYPE="button" VALUE="Open a message window"
onClick = "window3=window.open('','messageWindow',
'scrollbars=yes,width=175, height=300')">
<P><INPUT TYPE="button" VALUE="Write to the message window"
onClick="window3.document.writeln('Hey there');
window3.document.close()">
<P><INPUT TYPE="button" VALUE="Close the message window"
onClick="window3.close()">
<P><INPUT TYPE="button" VALUE="Close window2"
onClick="window2.close()">
</FORM>
</BODY>
</HTML>
win2.html, which defines
the content for window2, contains the following code:
<HTML>
<HEAD>
<TITLE>Window object example: Window 2</TITLE>
</HEAD>
<BODY BGCOLOR="oldlace"
onLoad="alert('Message from ' + window.name + ': Hello, World.')"
onUnload="alert('Message from ' + window.name + ': I\'m closing')">
<B>Some numbers</B>
<UL><LI>one
<LI>two
<LI>three
<LI>four</UL>
</BODY>
</HTML>
See also the example for the
Frame object.
1. window.propertyName 2. window.methodName
propertyName is the length or name property when the calling window refers to a Frame object.
methodName is any method associated with the window object.
Although you can use the window property as a synonym for the current frame, your code is more readable if you use the self property. For example, window.name and self.name both specify the name of the current frame, but self.name is easier to understand.
Use the window property to disambiguate a property of the window object from a form or form element of the same name. You can also use the window property to make your code more readable.
The window property is read-only. The value of the window property is
<object nameAttribute>where nameAttribute is the NAME attribute if window refers to a frame, or an internal reference if window refers to a window.
<A HREF="" onClick="this.href=pickRandomURL()" onMouseOver="window.status='Pick a random URL' ; return true"> Go!</A>
document.write(expression1 [,expression2], ...[,expressionN])
The write method is the same as the writeln method, except the write method does not append a newline character to the end of the output.
Use the write method within any <SCRIPT> tag or within an event handler. Event handlers execute after the original document closes, so the write method will implicitly open a new document of mimeType text/html if you do not explicitly issue a document.open() method in the event handler.
You can use the write method to generate HTML and JavaScript code. However, the HTML parser reads the generated code as it is being written, so you might have to escape some characters. For example, the following write method generates a comment and writes it to window2:
window2=window.open('','window2')
beginComment="\<!--"
endComment="--\>"
window2.document.write(beginComment)
window2.document.write(" This some text inside a comment. ")
window2.document.write(endComment)
To view HTML code that was generated with JavaScript write and writeln methods, the user must specify the view-source: protocol. If the user chooses Document Source or Frame Source from the View menu, the content displayed is that of the wysiwyg: URL. The following example shows a view-source: URL:
view-source:wysiwyg://0/file:/c|/temp/genhtml.htmlFor information on specifying the view-source: protocol in the location object, see the location object.
var mystery = "world"
// Displays Hello world testing 123
msgWindow.document.write("Hello ", mystery, " testing ", 123)
In the following example, the
write method takes two arguments. The first argument is an assignment
expression, and the second argument is a string literal.
//Displays Hello world... msgWindow.document.write(mystr = "Hello " + "world...")In the following example, the write method takes a single argument that is a conditional expression. If the value of the variable age is less than 18, the method displays "Minor." If the value of age is greater than or equal to 18, the method displays "Adult."
msgWindow.document.write(status = (age >= 18) ? "Adult" : "Minor")
document.writeln(expression1 [,expression2], ...[,expressionN])
The writeln method is the same as the write method, except the writeln method appends a newline character to the end of the output. HTML ignores the newline character, except within certain tags such as <PRE>.
Use the writeln method within any <SCRIPT> tag or within an event handler. Event handlers execute after the original document closes, so the writeln method will implicitly open a new document of mimeType text/html if you do not explicitly issue a document.open() method in the event handler.