1. Math.propertyName
2. Math.methodName(parameters)
Math.PI
. Constants are defined with the full precision of real numbers in JavaScript. Similarly, you reference Math functions as methods. For example, the sine function is Math.sin(argument)
, where argument is the argument.
It is often convenient to use the with statement when a section of code uses several Math constants and methods, so you don't have to type "Math" repeatedly. For example,
with (Math) {
a = PI * r*r
y = r*sin(theta)
x = r*cos(theta)
}
|
|
Methods
The Math object has the following methods:
|
|
|
Event handlers
None.
Examples
See the examples for the individual properties and methods.
Math.max(number1, number2)
Implemented in
Navigator 2.0
Examples
The following function evaluates the variables x and y:
function getMax(x,y) {
If you pass getMax the values 10 and 20, it returns 20; if you pass it the values -10 and -20, it returns -10.
return Math.max(x,y)
} See also
min method
Number.MAX_VALUE
Implemented in
Navigator 3.0
Tainted?
No
Description
The maximum numeric value representable in JavaScript
The MAX_VALUE property has a value of approximately 1.79E+308. Values larger than MAX_VALUE are represented as "Infinity".
Because MAX_VALUE is a constant, it is a read-only property of Number.
Examples
The following code multiplies two numeric values. If the result is less than or equal to MAX_VALUE, the func1 function is called; otherwise, the func2 function is called.
if (num1 * num2 <= Number.MAX_VALUE)
func1()
else
func2() See also
MIN_VALUE, NaN, NEGATIVE_INFINITY, POSITIVE_INFINITY properties
formName.method
Implemented in
Navigator 2.0
Tainted?
No
Description
The method property is a reflection of the METHOD attribute of the <FORM> tag. The method property should evaluate to either "get" or "post."
You can set the method property at any time.
Examples
The following function returns the value of the musicForm method property:
function getMethod() {
return document.musicForm.method
} See also
action, encoding, target properties; Form object
navigator.mimeTypes[index].propertyName
The MimeType object is a member of the mimeTypes array; each Plugin object also has an array of MimeType objects.
Implemented in
Navigator 3.0
Description
Each MimeType object is an element in the mimeTypes array.
For example, the following table summarizes the values for displaying JPEG images:
The mimeTypes array
The mimeTypes array contains an entry for each MIME type supported by the client (either internally, via helper applications, or by plug-ins). For example, if a client supports three MIME types, these MIME types are reflected as navigator.mimeTypes[0]
, navigator.mimeTypes[1]
, and navigator.mimeTypes[2]
.
Each element of the mimeTypes array is a MimeType object.
To use the mimeTypes array:
1. navigator.mimeTypes[index]
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).
To obtain the number of MIME types supported by the client, use the length property:
2. navigator.mimeTypes.lengthnavigator.mimeTypes.length
.
Elements in the mimeTypes array are read-only. For example, the statement navigator.mimeTypes[0]="video/quicktime"
has no effect.
The mimeTypes array used with the Plugin object
Each Plugin object has its own mimeTypes array, which contains an entry for each MIME type handled by the plug-in. For information, see Plugin.
Properties
The MimeType object has the following properties:
The mimeTypes array has the following properties:
Property |
Description
length
|
Reflects the number of MIME types supported by the
client
| |
---|
document.writeln("<TABLE BORDER=1><TR VALIGN=TOP>",The preceding example displays output similar to the following:
"<TH ALIGN=left>i",
"<TH ALIGN=left>type",
"<TH ALIGN=left>description",
"<TH ALIGN=left>suffixes",
"<TH ALIGN=left>enabledPlugin.name</TR>")
for (i=0; i < navigator.mimeTypes.length; i++) {
document.writeln("<TR VALIGN=TOP><TD>",i,
"<TD>",navigator.mimeTypes[i].type,
"<TD>",navigator.mimeTypes[i].description,
"<TD>",navigator.mimeTypes[i].suffixes)
if (navigator.mimeTypes[i].enabledPlugin==null) {
document.writeln(
"<TD>None",
"</TR>")
} else {
document.writeln(
"<TD>",navigator.mimeTypes[i].enabledPlugin.name,
"</TR>")
}
}
document.writeln("</TABLE>")
Math.min(number1, number2)
Implemented in
Navigator 2.0
Examples
The following function evaluates the variables x and y:
function getMin(x,y) {
If you pass getMin the values 10 and 20, it returns 10; if you pass it the values -10 and -20, it returns -20.
return Math.min(x,y)
} See also
max method
Number.MIN_VALUE
Implemented in
Navigator 3.0
Tainted?
No
Description
The MIN_VALUE property is the number closest to zero, not the most negative number, that JavaScript can represent.
MIN_VALUE has a value of approximately 2.22E-308. Values smaller than MIN_VALUE ("underflow values") are converted to zero.
Because MIN_VALUE is a constant, it is a read-only property of Number.
Examples
The following code divides two numeric values. If the result is greater than or equal to MIN_VALUE, the func1 function is called; otherwise, the func2 function is called.
if (num1 / num2 >= Number.MIN_VALUE)
func1()
else
func2() See also
MAX_VALUE, NaN, NEGATIVE_INFINITY, POSITIVE_INFINITY properties
1. objectName.name
2. frameReference.name
3. frameReference.frames.name
4. radioName[index].name
5. imageName.name
6. navigator.plugins[index].name
7. windowReference.name
8. windowReference.frames.name
name is a read-only property.
Image and Plugin objects
The name property for Image and Plugin objects is represented by forms 5-6 of the syntax.
newWindow=window.open("http://home.netscape.com")In the following example, the first statement creates a window called netscapeWin. The second statement displays the value "netscapeHomePage" in the Alert dialog box, because "netscapeHomePage" is the value of the windowName argument of netscapeWin.
function valueGetter() {
var msgWindow=window.open("")
for (var i = 0; i < newWindow.document.valueTest.elements.length; i++) {
msgWindow.document.write(newWindow.document.valueTest.elements[i].name + "<BR>")
}
}
netscapeWin=window.open("http://home.netscape.com","netscapeHomePage")For Plugin objects, see the examples for the Plugin object.
alert(netscapeWin.name)
For Plugin: description, filename, length properties
Number.NaN
Implemented in
Navigator 3.0
Tainted?
No
Description
JavaScript prints the value Number.NaN
as NaN
.
NaN always compares unequal to any other number, including NaN itself; you cannot check for the not-a-number value by comparing to Number.NaN. Use the isNaN function insead.
You might use the NaN property to indicate an error condition for a function that should return a valid number.
Because NaN is a constant, it is a read-only property of Number.
Examples
In the following example, if month has a value greater than 12, it is assigned NaN, and a message is displayed indicating valid values.
var month = 13
if (month < 1 || month > 12) {
month = Number.NaN
alert("Month must be between 1 and 12.")
} See also
MAX_VALUE, MIN_VALUE, NEGATIVE_INFINITY, POSITIVE_INFINITY properties; isNaN, parseFloat, parseInt functions
1. navigator.propertyName
2. navigator.methodName
Methods
The navigator object has the following methods:
|
|
Event handlers
None.
Examples
See the examples for the individual properties and methods.
Number.NEGATIVE_INFINITY
Implemented in
Navigator 3.0
Tainted?
No
Description
This value behaves mathematically like an infinity; for example, anything multiplied by infinity is infinity, and anything divided by infinity is zero.
Because NEGATIVE_INFINITY is a constant, it is a read-only property of Number.
Examples
In the following example, the variable smallNumber is assigned a value that is smaller than the minimum value. When the if statement executes, smallNumber has the value "-Infinity", so the func1 function is called.
var smallNumber = -Number.MAX_VALUE*10
if (smallNumber == Number.NEGATIVE_INFINITY)
func1()
else
func2() See also
MAX_VALUE, MIN_VALUE, NaN, POSITIVE_INFINITY properties
history.next
Implemented in
Navigator 3.0
Tainted?
Yes
Description
The next property reflects the URL that would be used if the user chose Forward from the Go menu. This property has a value only if data tainting is enabled; if data tainting is not enabled, next has no value.
next is a read-only property.
Examples
The following example determines whether history.next contains the string "NETSCAPE.COM". If it does, the function myFunction is called.
if (history.next.indexOf("NETSCAPE.COM") != -1) {
myFunction(history.next)
} See also
current, previous properties; "Using data tainting for security"
numberObjectName = new Number()To use a Number object:
numberObjectName.propertyName
biggestNum = Number.MAX_VALUENote that these properties are properties of the Number() constructor itself, not of individual Number objects. Example 2. The following example creates a Number object, myNum, then adds a description property to all Number objects. Then a value is assigned to the myNum object's description property.
smallestNum = Number.MIN_VALUE
infiniteNum = Number.POSITIVE_INFINITY
negInfiniteNum = Number.NEGATIVE_INFINITY
notANum = Number.NaN
myNum = new Number(65)
Number.prototype.description=null
myNum.description="wind speed"
Implemented in
Navigator 3.0
Examples
In the following example, an onAbort handler in an Image object displays a message when the user aborts the image load:
<IMG NAME="aircraft" SRC="f15e.gif"
onAbort="alert('You didn\'t get to see the image!')"> See also
onError, onLoad event handlers
Note
On some platforms, placing an onBlur event handler in a <FRAMESET> tag has no effect. Please see the release notes (after starting Netscape, choose Release Notes from the Help menu).See the relevant objects for the onBlur syntax.
<INPUT TYPE="text" VALUE="" NAME="userName" onBlur="required(this.value)">Example 2: Change the background color of a window. In the following example, a window's onBlur and onFocus event handlers change the window's background color depending on whether the window has focus.
<BODY BGCOLOR="lightgrey"Example 3: Change the background color of a frame. The following example creates four frames. The source for each frame,
onBlur="document.bgColor='lightgrey'"
onFocus="document.bgColor='antiquewhite'">
onblur2.html
has the <BODY> tag with the onBlur and onFocus event handlers shown in Example 1. When the document loads, all frames are "lightgrey". When the user clicks a frame, the onFocus event handler changes the frame's background color to "antiquewhite". The frame that loses focus is changed to "lightgrey". Note that the onBlur and onFocus event handlers are within the <BODY> tag, not the <FRAME> tag.
<FRAMESET ROWS="50%,50%" COLS="40%,60%">The following code has the same effect as the previous code, but is implemented differently. The onFocus and onBlur event handlers are associated with the frame, not the document. The onBlur and onFocus event handlers for the frame are specified by setting the onblur and onfocus properties. For information on using new to specify a string of JavaScript code to be compiled as a function, see the Function object.
<FRAME SRC=onblur2.html NAME="frame1">
<FRAME SRC=onblur2.html NAME="frame2">
<FRAME SRC=onblur2.html NAME="frame3">
<FRAME SRC=onblur2.html NAME="frame4">
</FRAMESET>
<SCRIPT>Example 4: Close a window. In the following example, a window's onBlur event handler closes the window when the window loses focus.
function setUpHandlers() {
for (var i = 0; i < frames.length; i++) {
frames[i].onfocus=new Function("document.bgColor='antiquewhite'")
frames[i].onblur=new Function("document.bgColor='lightgrey'")
}
}
</SCRIPT>
<FRAMESET ROWS="50%,50%" COLS="40%,60%" onLoad=setUpHandlers()>
<FRAME SRC=onblur2.html NAME="frame1">
<FRAME SRC=onblur2.html NAME="frame2">
<FRAME SRC=onblur2.html NAME="frame3">
<FRAME SRC=onblur2.html NAME="frame4">
</FRAMESET>
<BODY onBlur="window.close()">
This is some text
</BODY>
<INPUT TYPE="text" VALUE="" NAME="userName" onChange="checkValue(this.value)">
<A HREF = "http://home.netscape.com/"Returning false in an onClick event handler for a button has no effect.
onClick="return confirm('Load Netscape home page?')">Netscape</A>
Note
On some platforms, returning false in an onClick event handler for a reset button has no effect. Please see the release notes (after starting Netscape, choose Release Notes from the Help menu).See the relevant objects for the onClick syntax.
<INPUT TYPE="button" VALUE="Calculate" onClick="compute(this.form)">In the preceding example, the keyword this refers to the current object; in this case, the Calculate button. The construct this.form refers to the form containing the button. For another example, suppose you have created a JavaScript function called pickRandomURL that lets you select a URL at random. You can use the onClick event handler of a link to specify a value for the HREF attribute of the <A> tag dynamically, as shown in the following example:
<A HREF=""In the above example, the onMouseOver event handler specifies a custom message for the Navigator status bar when the user places the mouse pointer over the Go! anchor. As this example shows, you must return true to set the window.status property in the onMouseOver event handler. Example 2: Cancel the checking of a checkbox. The following example creates a checkbox with an onClick event handler. The event handler displays a confirm that warns the user that checking the checkbox purges all files. If the user chooses Cancel, the onClick event handler returns false and the checkbox is not checked.
onClick="this.href=pickRandomURL()"
onMouseOver="window.status='Pick a random URL'; return true">
Go!</A>
<INPUT TYPE="checkbox" NAME="check1" VALUE="check1"
onClick="return confirm('This purges all your files. Are you sure?')"> Remove files
window.location.href='notThere.html'
and notThere.html
does not exist, the resulting error message is a Navigator error message; therefore, an onError event handler would not intercept that message. However, an error event is triggered by a bad URL within an <IMG> tag or by corrupted image data.
window.onerror
applies only to errors that occur in the window containing window.onerror
, not in other windows.
The onError event handler can be any of the following:
window.onerror
to null means your users won't see JavaScript errors caused by your own code.
Implemented in
Navigator 3.0
Examples
Example 1: Null event handler. In the following <IMG> tag, the code onError="null"
suppresses error messages if errors occur when the image loads.
<IMG NAME="imageBad1" SRC="corrupt.gif" ALIGN="left" BORDER="2"
Example 2: Null event handler for a window. The onError event handler for windows cannot be expressed in HTML. Therefore, you must spell it all lowercase and set it in a <SCRIPT> tag. The following code assigns null to the onError handler for the entire window, not just the Image object. This suppresses all JavaScript error messages, including those for the Image object.
onError="null"><SCRIPT>
However, if the Image object has a custom onError event handler, the handler would execute if the image had an error. This is because
window.onerror=null
</SCRIPT>
<IMG NAME="imageBad1" SRC="corrupt.gif" ALIGN="left" BORDER="2">window.onerror=null
suppresses JavaScript error messages, not onError event handlers.
<SCRIPT>
In the following example,
window.onerror=null
function myErrorFunc() {
alert("The image had a nasty error.")
}
</SCRIPT>
<IMG NAME="imageBad1" SRC="corrupt.gif" ALIGN="left" BORDER="2"
onError="myErrorFunc()">window.onerror=null
suppresses all error reporting. Without onerror=null
, the code would cause a stack overflow error because of infinite recursion.
<SCRIPT>
Example 3: Error handling function. The following example defines a function, myOnError, that intercepts JavaScript errors. The function uses three arrays to store the message, URL, and line number for each error. When the user clicks the Display Error Report button, the displayErrors function opens a window and creates an error report in that window. Note that the function returns true to suppress the standard JavaScript error dialog.
window.onerror = null;
function testErrorFunction() {
testErrorFunction();
}
</SCRIPT>
<BODY onload="testErrorFunction()">
test message
</BODY><SCRIPT>
This example produces the following output:
window.onerror = myOnError
msgArray = new Array()
urlArray = new Array()
lnoArray = new Array()
function myOnError(msg, url, lno) {
msgArray[msgArray.length] = msg
urlArray[urlArray.length] = url
lnoArray[lnoArray.length] = lno
return true
}
function displayErrors() {
win2=window.open('','window2','scrollbars=yes')
win2.document.writeln('<B>Error Report</B><P>')
for (var i=0; i < msgArray.length; i++) {
win2.document.writeln('<B>Error in file:</B> ' + urlArray[i] + '<BR>')
win2.document.writeln('<B>Line number:</B> ' + lnoArray[i] + '<BR>')
win2.document.writeln('<B>Message:</B> ' + msgArray[i] + '<P>')
}
win2.document.close()
}
</SCRIPT>
<BODY onload="noSuchFunction()">
<FORM>
<BR><INPUT TYPE="button" VALUE="This button has a syntax error"
onClick="alert('unterminated string)">
<P><INPUT TYPE="button" VALUE="Display Error Report"
onClick="displayErrors()">
</FORM>Error Report
Error in file: file:///c%7C/temp/onerror.html
Line number: 34
Message: unterminated string literalError in file: file:///c%7C/temp/onerror.html
Line number: 34
Message: missing ) after argument listError in file: file:///c%7C/temp/onerror.html
Example 4: Event handler calls a function. In the following <IMG> tag, the onError event handler calls the function badImage if errors occur when the image loads.
Line number: 30
Message: noSuchFunction is not defined<SCRIPT>
function badImage(theImage) {
alert('Error: ' + theImage.name + ' did not load properly.')
}
</SCRIPT>
<FORM>
<IMG NAME="imageBad2" SRC="orca.gif" ALIGN="left" BORDER="2"
onError="badImage(this)">
</FORM> See also
onAbort, onLoad event handlers
Note
On some platforms, placing an 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).See the relevant objects for the onFocus syntax.
<INPUT TYPE="textarea" VALUE="" NAME="valueField" onFocus="valueCheck()">See also the examples for the onBlur event handler.
See also
onBlur, onChange event handlers
BODY onLoad="...">
.
In a FRAMESET and FRAME relationship, an onLoad event within a frame (placed in the <BODY> tag) occurs before an onLoad event within the FRAMESET (placed in the <FRAMESET> tag).
For images, the onLoad event handler indicates the script to execute when an image is displayed. Do not confuse displaying an image with loading an image. You can load several images, then display them one by one in the same Image object by setting the object's src property. If you change the image displayed in this way, the onLoad event handler executes every time an image is displayed, not just when the image is loaded into memory.
If you specify an onLoad event handler for an Image object that displays a looping GIF animation (multi-image GIF), each loop of the animation triggers the onLoad event, and the event handler executes once for each loop.
You can use the onLoad event handler to create a JavaScript animation by repeatedly setting the src property of an Image object. See the Image object for information.
<BODY onLoad="window.alert("Welcome to the Brave New World home page!")>Example 2: Display alert when image loads. The following example creates two Image objects, one with the Image() constructor and one with the <IMG> tag. Each Image object has an onLoad event handler that calls the displayAlert function, which displays an alert. For the image created with the <IMG> tag, the alert displays the image name. For the image created with the Image() constructor, the alert displays a message without the image name. This is because the onLoad handler for an object created with the Image() constructor must be the name of a function, and it cannot specify parameters for the displayAlert function.
<SCRIPT>Example 3: Looping GIF animation. The following example displays an image,
imageA = new Image(50,50)
imageA.onload=displayAlert
imageA.src="cyanball.gif"
function displayAlert(theImage) {
if (theImage==null) {
alert('An image loaded')
}
else alert(theImage.name + ' has been loaded.')
}
</SCRIPT>
<IMG NAME="imageB" SRC="greenball.gif" ALIGN="top"
onLoad=displayAlert(this)><BR>
birdie.gif
, that is a looping GIF animation. The onLoad event handler for the image increments the variable cycles, which keeps track of the number of times the animation has looped. To see the value of cycles, the user clicks the button labeled Count Loops.
<SCRIPT>Example 4: Change GIF animation displayed. The following example uses an onLoad event handler to rotate the display of six GIF animations. Each animation is displayed in sequence in one Image object. When the document loads,
var cycles=0
</SCRIPT>
<IMG ALIGN="top" SRC="birdie.gif" BORDER=0
onLoad="++cycles">
<INPUT TYPE="button" VALUE="Count Loops"
onClick="alert('The animation has looped ' + cycles + ' times.')">
!anim0.html
is displayed. When that animation completes, the onLoad event handler causes the next file, !anim1.html
, to load in place of the first file. After the last animation, !anim5.html
, completes, the first file is again displayed. Notice that the changeAnimation function does not call itself after changing the src property of the Image object. This is because when the src property changes, the image's onLoad event handler is triggered and the changeAnimation function is called.
<SCRIPT>See also the examples for the Image object.
var whichImage=0
var maxImages=5
function changeAnimation(theImage) {
++whichImage
if (whichImage <= maxImages) {
var imageName="!anim" + whichImage + ".gif"
theImage.src=imageName
} else {
whichImage=-1
return
}
}
</SCRIPT>
<IMG NAME="changingAnimation" SRC="!anim0.gif" BORDER=0 ALIGN="top"
onLoad="changeAnimation(this)">
Implemented in
Navigator 3.0
Examples
See the examples for the Link object.
See also
onMouseOver event handler
<A HREF="http://home.netscape.com/"See onClick for an example of using onMouseOver when the <A> tag's HREF attribute is set dynamically.
onMouseOver="window.status='Click this if you dare!'; return true">
Click me</A>
See also the examples for the Link object.
See also
onMouseOut event handler
Implemented in
Navigator 3.0
Examples
The following example displays a Text object with the default value "CA" and a reset button. If the user types a state abbreviation in the Text object and then clicks the reset button, the original value of "CA" is restored. The form's onReset event handler displays a message indicating that defaults have been restored.
<FORM NAME="form1" onReset="alert('Defaults have been restored.')">
State:
<INPUT TYPE="text" NAME="state" VALUE="CA" SIZE="2"><P>
<INPUT TYPE="reset" VALUE="Clear Form" NAME="reset1">
</FORM> See also
reset method, Reset object
Implemented in
Navigator 2.0
Examples
The following example uses an onSelect handler in the valueField Text object to call the selectState function.
<INPUT TYPE="text" VALUE="" NAME="valueField" onSelect="selectState()">
Implemented in
Navigator 2.0
Examples
In the following example, the onSubmit event handler calls the validate function to evaluate the data being submitted. If the data is valid, the form is submitted; otherwise, the form is not submitted.
<FORM onSubmit="return validate(this)">
See also the examples for the Form object.
...
</FORM>
See also
Submit object, submit method
BODY onUnload="...">
.
In a frameset and frame relationship, an onUnload event within a frame (placed in the <BODY> tag) occurs before an onUnload event within the frameset (placed in the <FRAMESET> tag).
Implemented in
Navigator 2.0
Examples
In the following example, the onUnload event handler calls the cleanUp function to perform some shutdown processing when the user exits a Web page:
<BODY onUnload="cleanUp()">
See also
onLoad event handler
document.open(["mimeType"])
[windowReference.]document.open("text/html","replace")
text/html
is the default.
text/html
specifies a document containing ASCII text with HTML formatting.
text/plain
specifies a document containing plain ASCII text with end-of-line characters to delimit displayed lines.
image/gif
specifies a document with encoded bytes constituting a GIF header and pixel data.
image/jpeg
specifies a document with encoded bytes constituting a JPEG header and pixel data.
image/x-bitmap
specifies a document with encoded bytes constituting a bitmap header and pixel data.
"replace" causes the new document to reuse the history entry that the previous document used. When you specify "replace" while opening a document, the target window's history length is not incremented even after you write and close.
Method of
document
document.close()
method. The close method causes text or images that were sent to layout to display. After using document.close()
, issue document.open()
again when you want to begin another output stream.
In Navigator 3.0, document.open() or document.open("text/html") clears the current document if it has finished loading. This is because this type of open call writes a default <BASE HREF=> tag so you can generate relative URLs based on the generating script's document base.
document.open("text/html","replace")
executes, history.current for the target window is the URL of document that executed document.open.
function windowWriter1() {Example 2. The following function calls document.open with the "replace" keyword to open a stream before issuing write methods. The HTML code in the write methods is written to msgWindow, replacing the current history entry. The history length of msgWindow is not incremented.
var myString = "Hello, world!"
msgWindow.document.open()
msgWindow.document.write("<P>" + myString)
msgWindow.document.close()
}
function windowWriter2() {The following code creates the msgWindow window and calls the function:
var myString = "Hello, world!"
msgWindow.document.open("text/html","replace")
msgWindow.document.write("<P>" + myString)
msgWindow.document.write("<P>history.length is " +
msgWindow.history.length)
msgWindow.document.close()
}
msgWindow=window.open('','',Example 3. In the following example, the probePlugIn function determines whether a user has the Shockwave plug-in installed:
'toolbar=yes,scrollbars=yes,width=400,height=300')
windowWriter2()
function probePlugIn(mimeType) {
var havePlugIn = false
var tiny = window.open("", "teensy", "width=1,height=1")
if (tiny != null) {
if (tiny.document.open(mimeType) != null)
havePlugIn = true
tiny.close()
}
return havePlugIn
}
var haveShockwavePlugIn = probePlugIn("application/x-director")
[windowVar = ][window].open("URL", "windowName", ["windowFeatures"])
toolbar[=yes|no]|[=1|0]You may use any subset of these options. Separate options with a comma. Do not put spaces between the options. The windowFeatures are:
location[=yes|no]|[=1|0]
directories[=yes|no]|[=1|0]
status[=yes|no]|[=1|0]
menubar[=yes|no]|[=1|0]
scrollbars[=yes|no]|[=1|0]
resizable[=yes|no]|[=1|0]
width=pixels
height=pixels
Implemented in
Navigator 2.0
Description
The open method opens a new Web browser window on the client, similar to choosing New Web Browser from the File menu of the Navigator. The URL argument specifies the URL contained by the new window. If URL is an empty string, a new, empty window is created.
In event handlers, you must specify window.open()
instead of simply using open()
. Due to the scoping of static objects in JavaScript, a call to open()
without specifying an object name is equivalent to document.open()
.
windowFeatures is an optional, comma-separated list of options for the new window. The Boolean windowFeatures options are set to true if they are specified without values, or as yes
or 1
. For example, open("", "messageWindow", "toolbar")
and open("", "messageWindow", "toolbar=1")
both set the toolbar option to true. If windowName does not specify an existing window and you do not specify windowFeatures, all Boolean windowFeatures are true by default. If you specify any item in windowFeatures, all other Boolean windowFeatures are false unless you explicitly specify them. After a window is open, you cannot use JavaScript to change the windowFeatures.
You can use open on an existing window, and if you pass the empty string for the URL, you will get a reference to the existing window, but not load anything into it. You can, for example, then look for properties in the window.
Examples
In the following example, the windowOpener function opens a window and uses write methods to display a message:
function windowOpener() {
The following is an onClick event handler that opens a new client window displaying the content specified in the file
msgWindow=window.open("","displayWindow","menubar=yes")
msgWindow.document.write
("<HEAD><TITLE>Message window</TITLE></HEAD>")
msgWindow.document.write
("<CENTER><BIG><B>Hello, world!</B></BIG></CENTER>")
}sesame.html
. The window opens with the specified option settings; all other options are false because they are not specified.
<FORM NAME="myform">
Notice the use of single quotes (') inside the onClick event handler.
<INPUT TYPE="button" NAME="Button1" VALUE="Open Sesame!"
onClick="window.open ('sesame.html', 'newWin',
'scrollbars=yes,status=yes,width=300,height=300')">
</FORM> See also
close (window object) method
window.opener
Implemented in
Navigator 3.0
Tainted?
No
Description
When a source document opens a destination window by calling the open method, the opener property specifies the window of the source document. Evaluate the opener property from the destination window.
This property persists across document unload in the opened window.
You can change the opener property at any time.
Examples
Example 1: Close the opener. The following code closes the window that opened the current window. When the opener window closes, opener is unchanged. However, window.opener.name
then evaluates to undefined.
window.opener.close()
Example 2: Evaluate the name of the opener. A window can determine the name of its opener as follows:
document.write("<BR>opener property is " + window.opener.name)
Example 3: Change the value of opener. The following code changes the value of the opener property to null. After this code executes, you cannot close the opener window as shown in Example 1.
window.opener=null
Example 4: Change a property of the opener. The following code changes the background color of the window specified by the opener property.
window.opener.document.bgColor='bisque'
See also
close (window object), open (window object) methods
1. parent.propertyName
2. parent.methodName
3. parent.frameName
4. parent.frames[index]
Implemented in
Navigator 2.0
Tainted?
No
Description
The parent property refers to the FRAMESET window of a frame. Child frames within a frameset refer to sibling frames by using "parent" in place of the window name as follows: parent.frameName
or parent.frames[index]
. For example, if the fourth frame in a set has NAME="homeFrame," sibling frames can refer to that frame using parent.homeFrame
or parent.frames[3]
.
You can use parent.parent
to refer to the "grandparent" frame or window when a <FRAMESET> tag is nested within a child frame.
The parent property is read-only. The value of the parent property is
<object nameAttribute>
where nameAttribute is the NAME attribute if the parent is a frame, or an internal reference if the parent is a window.
Examples
See the examples for the Frame object.
Date.parse(dateString)
Implemented in
Navigator 2.0
Description
The parse method takes a date string (such as "Dec 25, 1995") and returns the number of milliseconds since January 1, 1970, 00:00:00 (local time). This function is useful for setting date values based on string values, for example in conjunction with the setTime method and the Date object.
Given a string representing a time, parse returns the time value. It accepts the IETF standard date syntax: "Mon, 25 Dec 1995 13:30:00 GMT." It understands the continental US time-zone abbreviations, but for general use, use a time-zone offset, for example, "Mon, 25 Dec 1995 13:30:00 GMT+0430" (4 hours, 30 minutes west of the Greenwich meridian). If you do not specify a time zone, the local time zone is assumed. GMT and UTC are considered equivalent.
Because the parse function is a static method of Date, you always use it as Date.parse()
, rather than as a method of a Date object you created.
Examples
If IPOdate is an existing Date object, then
IPOdate.setTime(Date.parse("Aug 9, 1995"))
See also
UTC method
parseFloat(string)
parseFloat("3.14")The following example returns "NaN":
parseFloat("314e-2")
parseFloat("0.0314E+2")
var x = "3.14"
parseFloat(x)
parseFloat("FF2")
parseInt(string [,radix])
parseInt("F", 16)The following examples all return "NaN":
parseInt("17", 8)
parseInt("15", 10)
parseInt(15.99, 10)
parseInt("FXX123", 16)
parseInt("1111", 2)
parseInt("15*3", 10)
parseInt("Hello", 8)Even though the radix is specified differently, the following examples all return 17 because the input string begins with "0x."
parseInt("0x7", 10)
parseInt("FFF", 10)
parseInt("0x11", 16)
parseInt("0x11", 0)
parseInt("0x11")
<INPUT
TYPE="password"
NAME="passwordName"
[VALUE="textValue"]
SIZE=integer
[onBlur="handlerText"]
[onFocus="handlerText"]>
1. passwordName.propertyName
2. passwordName.methodName(parameters)
3. formName.elements[index].propertyName
4. formName.elements[index].methodName(parameters)
A Password object is a form element and must be defined within a <FORM> tag. If a user interactively modifies the value in a password field, you cannot evaluate it accurately unless data tainting is enabled. See "Using data tainting for security" and the value property.
Properties
The Password object has the following properties:
Methods
The Password object has the following methods:
|
|
<B>Password:</B> <INPUT TYPE="password" NAME="password" VALUE="" SIZE=25>
1. links[index].pathname
2. location.pathname
3. areaName.pathname
window.location.pathname
instead of simply using location.pathname
. 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
.
See Section 3.1 of RFC 1738 for complete information about the pathname.
Examples
See the examples for the href property.
See also
hash, host, hostname, href, port, protocol, search properties
Math.PI
Implemented in
Navigator 2.0
Tainted?
No
Description
Because PI is a constant, it is a read-only property of Math.
Examples
The following function returns the value of pi:
function getPi() {
return Math.PI
} See also
E, LN2, LN10, LOG2E, LOG10E, SQRT1_2, SQRT2 properties
1. navigator.plugins[index].propertyName
2. navigator.plugins[pluginIndex][mimeTypeIndex].mimeTypePropertyName
The Plugin object is a member of the plugins array.
Implemented in
Navigator 3.0
Description
A Plugin object is a plug-in installed on the client. A plug-in is a software module that Navigator can invoke to display specialized types of embedded data within the browser. The user can obtain a list of installed plug-ins by choosing About Plug-ins from the Help menu.
Each Plugin object is an array containing one element for each MIME type supported by the plug-in. Each element of the array is a MimeType object. You can access the MimeType objects using form 2 of the syntax. For example, the following code displays the type and description properties of the first Plugin object's first MimeType object.
myPlugin=navigator.plugins[0]
The preceding code displays output similar to the following:
myMimeType=myPlugin[0]
document.writeln('myMimeType.type is ',myMimeType.type,"<BR>")
document.writeln('myMimeType.description is ',myMimeType.description)myMimeType.type is video/quicktime
The Plugin object lets you dynamically determine which plug-ins are installed on the client. You can write scripts to display embedded plug-in data if the appropriate plug-in is installed, or display some alternative information such as images or text if not.
Plug-ins can be platform dependent and configurable, so a Plugin object's array of MimeType objects can vary from platform to platform, and from user to user.
Each Plugin object is an element in the plugins array.
When you use the <EMBED> tag to generate output from a plug-in application, you are not creating a Plugin object. Use the embeds array to reference plug-in instances created with <EMBED> tags. See the embeds array.
myMimeType.description is QuickTime for Windows
The plugins array
You can reference the Plugin objects installed on the client by using the plugins array. This array contains an entry for each plug-in installed on the client in source order. Each element of the plugins array is a Plugin object. For example, if three plug-ins are installed on the client, these plug-ins are reflected as navigator.plugins[0]
, navigator.plugins[1]
, and navigator.plugins[2]
.
To use the plugins array:
1. navigator.plugins[index]
index is an integer representing a plug-in installed on the client or a string containing the name of a Plugin object (from the name property).
To obtain the number of plug-ins installed on the client, use the length property:
2. navigator.plugins.lengthnavigator.plugins.length
.
Elements in the plugins array are read-only. For example, the statement navigator.plugins[0]="LiveAudio"
has no effect.
Properties
The Plugin object has the following properties:
The plugins array has the following properties:
Property |
Description
length
|
Reflects the number of plug-ins installed on the client
| |
---|
Methods
The Plugin object has the following methods:
The plugins array has the following methods:
var myPluginName = navigator.plugins["LiveAudio"].nameExample 3. The following code displays the message "LiveAudio is configured for audio/wav" if the LiveAudio plug-in is installed and is enabled for the "audio/wav" MIME type:
var myPluginFile = navigator.plugins["LiveAudio"].filename
var myPluginDesc = navigator.plugins["LiveAudio"].description
var myPlugin = navigator.plugins["LiveAudio"]Example 4. The following expression represents the number of MIME types that Shockwave can display:
var myType = myPlugin["audio/wav"]
if (myType && myType.enabledPlugin == myPlugin)
document.writeln("LiveAudio is configured for audio/wav")
navigator.plugins["Shockwave"].lengthExample 5. The following code displays the name, filename, description, and length properties for each Plugin object on a client:
document.writeln("<TABLE BORDER=1><TR VALIGN=TOP>",The preceding example displays output similar to the following:
"<TH ALIGN=left>i",
"<TH ALIGN=left>name",
"<TH ALIGN=left>filename",
"<TH ALIGN=left>description",
"<TH ALIGN=left># of types</TR>")
for (i=0; i < navigator.plugins.length; i++) {
document.writeln("<TR VALIGN=TOP><TD>",i,
"<TD>",navigator.plugins[i].name,
"<TD>",navigator.plugins[i].filename,
"<TD>",navigator.plugins[i].description,
"<TD>",navigator.plugins[i].length,
"</TR>")
}
document.writeln("</TABLE>")
See also
MimeType object; embeds array
1. links[index].port
2. location.port
3 areaName.port
window.location.port
instead of simply using location.port
. 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
.
See Section 3.1 of RFC 1738 for complete information about the port.
Examples
See the examples for the href property.
See also
hash, host, hostname, href, pathname, protocol, search properties
Number.POSITIVE_INFINITY
Implemented in
Navigator 3.0
Tainted?
No
Description
This value behaves mathematically like an infinity; for example, anything multiplied by infinity is infinity, and anything divided by infinity is zero.
JavaScript does not have a literal for Infinity.
Because POSITIVE_INFINITY is a constant, it is a read-only property of Number.
Examples
In the following example, the variable bigNumber is assigned a value that is larger than the maximum value. When the if statement executes, bigNumber has the value "Infinity", so the func1 function is called.
var bigNumber = Number.MAX_VALUE * 10
if (bigNumber == Number.POSITIVE_INFINITY)
func1()
else
func2() See also
MAX_VALUE, MIN_VALUE, NaN, NEGATIVE_INFINITY properties
Math.pow(base, exponent)
Implemented in
Navigator 2.0
Examples
function raisePower(x,y) {
If x equals seven and y equals two, raisePower returns 49 (seven to the power of two).
return Math.pow(x,y)
} See also
exp, log methods
history.previous
Implemented in
Navigator 3.0
Tainted?
Yes
Description
The previous property reflects the URL that would be used if the user chose Back from the Go menu. This property has a value only if data tainting is enabled; if data tainting is not enabled, previous has no value.
previous is a read-only property.
Examples
The following example determines whether history.previous contains the string "NETSCAPE.COM". If it does, the function myFunction is called.
if (history.previous.indexOf("NETSCAPE.COM") != -1) {
myFunction(history.previous)
} See also
current, next properties; "Using data tainting for security"
prompt(message, [inputDefault])
Implemented in
Navigator 2.0
Description
A prompt dialog box looks as follows:windowReference.prompt()
is unnecessary.
You cannot specify a title for a prompt dialog box, but you can use the open method to create your own "prompt" dialog. See open (window object).
Examples
prompt("Enter the number of cookies you want to order:", 12)
See also
alert, confirm methods
1. links[index].protocol
2. location.protocol
3 areaName.protocol
window.location.protocol
instead of simply using location.protocol
. 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
.
The protocol property represents the scheme name of the URL. See Section 2.1 of RFC 1738 for complete information about the protocol.
Examples
See the examples for the href property.
See also
hash, host, hostname, href, pathname, port, search properties
objectType.prototype.propertyName = value
|
|
Implemented in
Navigator 3.0
Tainted?
No
Description
Use the prototype property to explicitly add properties to objects created with the new operator.
For example, you can create Date objects by using the Date() constructor and the new operator. Date.prototype
refers to the prototype object for the Date() constructor. If you set a property for the prototype, such as Date.prototype.description
, then all objects created with Date() will have the description property, even if the objects already exist.
var today = new Date()
After you set a property for the prototype, all subsequent objects created with Date() will have the property:
var birthday = new Date(95,12,17)
Date.prototype.description=null
today.description="Oh what a beautiful mornin\'"
birthday.description="The day you were born"startDate=new Date()
startDate.description="Started the daily grind" Examples
Example 1: Add a property to a user-defined object. The following example uses the function Car to define a Car object type. It then uses new to create myCar, an instance of the object. The code Car.prototype.wheels=4
adds the wheels property to all instances of the Car object.
function Car(make, model, year) {
Example 2: Add a method to String objects. The following example creates a method, str_rep, and uses the statement
this.make = make
this.model = model
this.year = year
}
var myCar = new Car("Acura", "Integra", 1987)
Car.prototype.wheels = 4 // no 3-wheelers please!
if (myCar.wheels == 4)
document.write("The car myCar has ", myCar.wheels, " wheels.")String.prototype.rep = str_rep
to add the method to all String objects. All objects created with new String()
then have that method, even objects already created. The example then creates an alternate method and adds that to one of the String objects using the statement s1.rep = fake_rep
. The str_rep method of the remaining String objects is not altered.
var s1 = new String("a")
This example produces the following output:
var s2 = new String("b")
var s3 = new String("c")
// Create a repeat-string-N-times method for all String objects
function str_rep(n) {
var s = "", t = this.toString()
while (--n >= 0) s += t
return s
}
String.prototype.rep = str_rep
// Display the results
document.write("<P>s1.rep(3) is " + s1.rep(3)) // "aaa"
document.write("<BR>s2.rep(5) is " + s2.rep(5)) // "bbbbb"
document.write("<BR>s3.rep(2) is " + s3.rep(2)) // "cc"
// Create an alternate method and assign it to only one String variable
function fake_rep(n) {
return "repeat " + this + n + " times."
}
s1.rep = fake_rep
document.write("<P>s1.rep(1) is " + s1.rep(1)) // "repeat a 1 times."
document.write("<BR>s2.rep(4) is " + s2.rep(4)) // "bbbb"
document.write("<BR>s3.rep(6) is " + s3.rep(6)) // "cccccc"s1.rep(3) is aaa
s2.rep(5) is bbbbb
s3.rep(2) is ccs1.rep(1) is repeat a1 times.
The function in this example also works on String objects not created with the String() constructor. The following code returns "zzz".
s2.rep(4) is bbbb
s3.rep(6) is cccccc"z".rep(3)
See also
constructor property; "Creating new objects"