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. Built-in objects do not have event handlers.
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 ten and twenty, it returns twenty; if you pass it the values -10 and -20, it returns -10.
return Math.max(x,y)
} See also
min method
formName.method
Implemented in
Navigator 2.0
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
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
You can reference the MimeType objects in your code by using the mimeTypes array. This array contains an entry for each MIME type supported by the client (either internally, via helper applications, or by plug-ins) in source order. 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 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.
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 |
|
---|
Methods
Event handlers
Examples
The following code displays the type, description, suffixes, and enabledPlugin properties for each MimeType 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>type",
"<TH ALIGN=left>description",
"<TH ALIGN=left>suffixes",
"<TH ALIGN=left>enabledPlugin</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>",navigator.mimeTypes[i].enabledPlugin,
"</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 ten and twenty, it returns ten; if you pass it the values -10 and -20, it returns -20.
return Math.min(x,y)
} See also
max method
1. objectName.name
2. frameReference.name
3. frameReference.frames.name
4. radioName[index].name
5. selectName.options.name
6. fileUploadName.name
7. imageName.name
8. navigator.plugins[index].name
9. windowReference.name
10. windowReference.frames.name
name is a read-only property.
FileUpload, Image, and Plugin objects
The name property for FileUpload, Image, and Plugin objects is represented by forms 6-8 of the syntax.
newWindow=window.open("http://www.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://www.netscape.com", "netscapeHomePage")For Plugin objects, see the examples for the Plugin object.
alert(netscapeWin.name)
For Plugin: description, filename, length properties
navigator.propertyName
Methods
Event handlers
None
Examples
See the examples for the individual properties.
See also
Anchor object, Link object
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.
Implemented in
Examples
Example 1: Validate form input. In the following example, userName is a required text field. When a user attempts to leave the field, the onBlur event handler calls the required function to confirm that userName has a legal value.
<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> See also
onChange, onFocus event handlers
Implemented in
Navigator 2.0
Examples
In the following example, userName is a text field. When a user attempts to leave the field, the onBlur event handler calls the checkValue function to confirm that userName has a legal value.
<INPUT TYPE="text" VALUE="" NAME="userName" onBlur="checkValue(this.value)">
See also
onBlur, onFocus event handlers
<A HREF = "http://www.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.
Implemented in
Examples
Example 1: Call a function when a user clicks a button. Suppose you have created a JavaScript function called compute. You can execute the compute function when the user clicks a button by calling the function in the onClick event handler, as follows:
<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.onerror
to null means your users won't see JavaScript errors caused by your own code.
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.
See the relevant objects for the onError syntax.
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.
onError="null"><SCRIPT>
In the following example,
window.onerror=null
</SCRIPT>
<IMG NAME="imageBad1" SRC="corrupt.gif" ALIGN="left" BORDER="2">window.onerror=null
suppresses all error reporting. Without onerror=null
, the code would cause a stack overflow error.
<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.
Implemented in
Examples
The following example uses an onFocus handler in the valueField Textarea object to call the valueCheck function.
<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.
Implemented in
Examples
Example 1: Display message when page loads. In the following example, the onLoad event handler displays a greeting message after a Web page is loaded.
<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)"> See also
onAbort, onError, onUnload event handlers
Implemented in
Navigator 3.0
Examples
See the examples for the Area object.
See also
onMouseOver event handler
Implemented in
Examples
By default, the HREF value of an anchor displays in the status bar at the bottom of the Navigator when a user places the mouse pointer over the anchor. In the following example, the onMouseOver event handler provides the custom message "Click this if you dare."
<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 Area 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"])
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.
Implemented in
Navigator 2.0
Description
The open method opens a stream to collect the output of write or writeln methods. If the mimeType is text or image, the stream is opened to layout; otherwise, the stream is opened to a plug-in. If a document exists in the target window, the open method clears it.
End the stream by using the 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.
Examples
The following function calls document.open()
to open a stream before issuing a write method:
function windowWriter1() {
In the following example, the probePlugIn function determines whether a user has the Shockwave plug-in installed:
var myString = "Hello, world!"
msgWindow.document.open()
msgWindow.document.write("<P>" + myString)
msgWindow.document.close()
}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") See also
close (document object), write, writeln methods
[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.
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
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 might want to clear the opener property to free otherwise closed windows in a chain of openers leading to the current one.
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.
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
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 seventeen 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>
1. passwordName.propertyName
2. passwordName.methodName(parameters)
3. formName.elements[index].propertyName
4. formName.elements[index].methodName(parameters)
Property |
Description
defaultValue |
Reflects the VALUE attribute |
name |
Reflects the NAME attribute |
type |
Reflects the TYPE attribute |
value |
Reflects the current value of the Password object's field |
|
---|
<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
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
<EMBED
SRC=source
NAME=appletName
HEIGHT=height
WIDTH=width>
[<PARAM NAME=parameterName VALUE=parameterValue>]
[ ... <PARAM>]
</EMBED>
1. navigator.plugins[index].propertyName
2. navigator.plugins[pluginIndex][mimeTypeIndex].propertyName
The embeds array is a property of document.
Implemented in
Navigator 3.0
Description
A Plugin object is a plug-in installed on the client. When you use the <EMBED> tag to generate output from a plug-in application, you are not creating a Plugin object.
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.
Each Plugin object is an element in the plugins array.
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.
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.
The embeds array
You can reference the <EMBED> tags your code by using the embeds array. This array contains an entry for each <EMBED> tag in a document in source order. For example, if a document contains three <EMBED> tags, these <EMBED> tags are reflected as document.embeds[0]
, document.embeds[1]
, and document.embeds[2]
.
To use the embeds array:
1. document.embeds[index]
index is an integer representing an <EMBED> tag in a document or a string containing the name of an embedded object (the NAME attribute of an <EMBED> tag).
To obtain the number of <EMBED> tags in a document, use the length property:
2. document.embeds.lengthdocument.embeds.length
.
Elements in the embeds array are read-only. For example, the statement document.embeds[0]="myavi.avi"
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 |
|
---|
The embeds array has the following properties:
Property |
Description
length |
Reflects the number of elements in the array |
|
---|
<EMBED SRC="train.au" HEIGHT=50 WIDTH=250>Example 2. The following code assigns shorthand variables for the predefined LiveAudio properties.
var myPlugin = navigator.plugins["LiveAudio"].nameExample 3. The following expression will be true if Shockwave has been configured to display QuickTime movies:
var myPluginFile = navigator.plugins["LiveAudio"].filename
var myPluginDesc = navigator.plugins["LiveAudio"].description
navigator.plugins["Shockwave"]["video/quicktime"]Example 4. The following expression represents the number of MIME types that Shockwave is configured to display:
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>length</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
Applet, MimeType objects
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
Math.pow(base, exponent)
Implemented in
Navigator 2.0
Examples
function raisePower(x,y) {
If x equals seven and y equals two, raisePower returns forty-nine (seven to the power of two).
return Math.pow(x,y)
} See also
exp, log methods
prompt(message, [inputDefault])
Implemented in
Navigator 2.0
Description
Use the prompt method to display a dialog box that receives user input. If you do not specify an initial value for inputDefault, the dialog box displays "<undefined>."
Although prompt is a method of the window object, you do not need to specify a windowReference when you call it. For example, windowReference.prompt()
is unnecessary.
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
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"
Car.prototype.wheels=4
adds the wheels property to all instances of the Car object.
function Car(make, model, year) {
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.")