1. dateObjectName = new Date()To use a Date object:
2. dateObjectName = new Date("month day, year hours:minutes:seconds")
3. dateObjectName = new Date(year, month, day)
4. dateObjectName = new Date(year, month, day, hours, minutes, seconds)
1. dateObjectName.propertyNameExceptions: The Date object's parse and UTC methods are static methods that you use as follows:
2. dateObjectName.methodName(parameters)
Date.UTC(parameters)
Date.parse(parameters)
Property |
Description
prototype |
Lets you add a properties to a Date object.
| |
---|
Methods
The Date object has the following methods:
Event handlers
None.
Examples
The following examples show several ways to assign dates:
today = new Date()
birthday = new Date("December 17, 1995 03:24:00")
birthday = new Date(95,12,17)
birthday = new Date(95,12,17,3,24,0)
1. checkboxName.defaultChecked
2. radioName[index].defaultChecked
Implemented in
Navigator 2.0
Tainted?
Yes
Description
If a checkbox or radio button is selected by default, the value of the defaultChecked property is true; otherwise, it is false. defaultChecked initially reflects whether the CHECKED attribute is used within an <INPUT> tag; however, setting defaultChecked overrides the CHECKED attribute.
You can set the defaultChecked property at any time. The display of the checkbox or radio button does not update when you set the defaultChecked property, only when you set the checked property.
Examples
The following example resets an array of radio buttons called musicType on the musicForm form to the default selection state:
function radioResetter() {
var i=""
for (i in document.musicForm.musicType) {
if (document.musicForm.musicType[i].defaultChecked==true) {
document.musicForm.musicType[i].checked=true
}
}
} See also
checked property
selectName.options[index].defaultSelected
optionName.defaultSelected
function restoreDefault() {The previous example assumes that the Select object is similar to the following:
for (var i = 0; i < document.musicForm.musicType.length; i++) {
if (document.musicForm.musicType.options[i].defaultSelected == true) {
document.musicForm.musicType.options[i].selected=true
}
}
}
<SELECT NAME="musicType">
<OPTION SELECTED> R&B
<OPTION> Jazz
<OPTION> Blues
<OPTION> New Age
</SELECT>
windowReference.defaultStatus
Implemented in
Navigator 2.0
Tainted?
Yes
Description
The defaultStatus message appears when nothing else is in the status bar. Do not confuse the defaultStatus property with the status property. The status property reflects a priority or transient message in the status bar, such as the message that appears when a mouseOver event occurs over an anchor.
You can set the defaultStatus property at any time. You must return true if you want to set the defaultStatus property in the onMouseOut or onMouseOver event handlers.
Examples
In the following example, the statusSetter function sets both the status and defaultStatus properties in an onMouseOver event handler:
function statusSetter() {
In the previous example, notice that the onMouseOver event handler returns a value of true. You must return true to set status or defaultStatus in an event handler.
window.defaultStatus = "Click the link for the Netscape home page"
window.status = "Netscape home page"
}
<A HREF="http://home.netscape.com"
onMouseOver = "statusSetter(); return true">Netscape</A> See also
status property
1. passwordName.defaultValue
2. textName.defaultValue
3. textareaName.defaultValue
Implemented in
Navigator 2.0
Tainted?
Yes
Description
The initial value of defaultValue differs for each object:
function defaultGetter() {
msgWindow=window.open("")
msgWindow.document.write("hidden.defaultValue is " +
document.surfCity.hiddenObj.defaultValue + "<BR>")
msgWindow.document.write("password.defaultValue is " +
document.surfCity.passwordObj.defaultValue + "<BR>")
msgWindow.document.write("text.defaultValue is " +
document.surfCity.textObj.defaultValue + "<BR>")
msgWindow.document.write("textarea.defaultValue is " +
document.surfCity.textareaObj.defaultValue + "<BR>")
msgWindow.document.close()
}
1. navigator.mimeTypes[index1].description
2. navigator.plugins[index2].description
For Plugin objects: filename, length, name properties
<BODY
BACKGROUND="backgroundImage"
BGCOLOR="backgroundColor"
TEXT="foregroundColor"
LINK="unfollowedLinkColor"
ALINK="activatedLinkColor"
VLINK="followedLinkColor"
[onBlur="handlerText"]
[onFocus="handlerText"]
[onLoad="handlerText"]
[onUnload="handlerText"]>
</BODY>
Syntax
To use a document object's properties and methods:
1. document.propertyName
2. document.methodName(parameters) Parameters
propertyName is one of the properties listed below.
methodName is one of the methods listed below.
Property of
window object
document.close(); document.open(); document.write()
. You can omit the document.open()
call if you are writing text or HTML, since write does an implicit open of that mime type if the document stream is closed.
You can reference the anchors, forms, and links of a document by using the anchors, forms, and links arrays. These arrays contain an entry for each anchor, form, or link in a document.
Do not use location as a property of the document object; use the document.URL property instead. The document.location property, which is a synonym for document.URL, will be removed in a future release.
The following objects are also properties of the document object:
|
|
Methods
The document object has the following methods:
|
|
Event handlers
None. The onBlur, onFocus, onLoad, and onUnload event handlers are specified in the <BODY> tag but are actually event handlers for the window object.
Examples
The following example creates two frames, each with one document. The document in the first frame contains links to anchors in the document of the second frame. Each document defines its colors.
doc0.html
, which defines the frames, contains the following code:
<HTML>
<HEAD>
<TITLE>Document object example</TITLE>
</HEAD>
<FRAMESET COLS="30%,70%">
<FRAME SRC="doc1.html" NAME="frame1">
<FRAME SRC="doc2.html" NAME="frame2">
</FRAMESET>
</HTML>doc1.html
, which defines the content for the first frame, contains the following code:
<HTML>
<SCRIPT>
</SCRIPT>
<BODY
BGCOLOR="antiquewhite"
TEXT="darkviolet"
LINK="fuchsia"
ALINK="forestgreen"
VLINK="navy">
<P><B>Some links</B>
<LI><A HREF="doc2.html#numbers" TARGET="frame2">Numbers</A>
<LI><A HREF="doc2.html#colors" TARGET="frame2">Colors</A>
<LI><A HREF="doc2.html#musicTypes" TARGET="frame2">Music types</A>
<LI><A HREF="doc2.html#countries" TARGET="frame2">Countries</A>
</BODY>
</HTML>doc2.html
, which defines the content for the second frame, contains the following code:
<HTML>
<SCRIPT>
</SCRIPT>
<BODY
BGCOLOR="oldlace" onLoad="alert('Hello, World.')"
TEXT="navy">
<P><A NAME="numbers"><B>Some numbers</B></A>
<UL><LI>one
<LI>two
<LI>three
<LI>four</UL>
<P><A NAME="colors"><B>Some colors</B></A>
<UL><LI>red
<LI>orange
<LI>yellow
<LI>green</UL>
<P><A NAME="musicTypes"><B>Some music types</B></A>
<UL><LI>R&B
<LI>Jazz
<LI>Soul
<LI>Reggae</UL>
<P><A NAME="countries"><B>Some countries</B></A>
<UL><LI>Afghanistan
<LI>Brazil
<LI>Canada
<LI>Finland</UL>
</BODY>
</HTML> See also
Frame object, window object
document.domain
Tainted?
Yes
Implemented in
Navigator 3.0
Description
The domain property lets scripts on multiple servers share properties when data tainting is not enabled. With tainting disabled, a script running in one window can read properties of another window only if both windows come from the same Web server. But large Web sites with multiple servers might need to share properties among servers. For example, a script on the host www.yahoo.com
might need to share properties with a script on the host search.yahoo.com
.
If scripts on two different servers change their domain property so that both scripts have the same domain name, both scripts can share properties. For example, a script loaded from search.yahoo.com
could set its domain property to "yahoo.com". A script from www.yahoo.com
running in another window could also set its domain property to "yahoo.com". Then, since both scripts have the domain "yahoo.com", these two scripts can share properties, even though they did not originate from the same server.
You can change domain only in a restricted way. Initially, domain contains the hostname of the Web server from which the document was loaded. You can set domain only to a domain suffix of itself. For example, a script from search.yahoo.com
can't set its domain property to "search.yahoo". And a script from IWantYourMoney.com
cannot set its domain to "yahoo.com".
Once you change the domain property, you cannot change it back to its original value. For example, if you change domain from "search.yahoo.com" to "yahoo.com", you cannot reset it to "search.yahoo.com".
You can change domain at any time.
Examples
The following statement changes the domain property to "braveNewWorld.com". This statement is valid only if "braveNewWorld.com" is a suffix of the current domain, such as "www.braveNewWorld.com".
document.domain="braveNewWorld.com"
See also
taint, untaint functions; "Using data tainting for security"
Math.E
Implemented in
Navigator 2.0
Tainted?
No
Description
Because E is a constant, it is a read-only property of Math.
Examples
The following function returns Euler's constant:
function getEuler() {
return Math.E
} See also
exp, LN2, LN10, LOG2E, LOG10E, PI, SQRT1_2, SQRT2 properties
1. formName.elements[index]
2. formName.elements.length
Implemented in
Navigator 2.0
Tainted?
No
Description
You can reference a form's elements in your code by using the elements array. This array contains an entry for each object (Button, Checkbox, FileUpload, Hidden, Password, Radio, Reset, Select, Submit, Text, or Textarea object) in a form in source order. For example, if a form has a text field and two checkboxes, these elements are reflected as formName.elements[0]
, formName.elements[1]
, and formName.elements[2]
.
Although you can also reference a form's elements by using the element's name (from the NAME attribute), the elements array provides a way to reference Form objects programmatically without using their names. For example, if the first object on the userInfo form is the userName Text object, you can evaluate it in either of the following ways:
userInfo.userName.value
To obtain the number of elements on a form, use the length property: formName
userInfo.elements[0].value.elements.length
. Each radio button in a Radio object appears as a separate element in the elements array.
Elements in the elements array are read-only. For example, the statement formName.elements[0]="music"
has no effect.
The value of each element in the elements array is the full HTML statement for the object.
Properties
The elements array has the following properties:
Property |
Description
length |
Reflects the number of elements in the form
| |
---|
Examples
See the examples for the Frame property.
<EMBEDFor the complete syntax of the <EMBED> tag, see http://home.netscape.com/eng/mozilla/3.0/handbook/plugins/index.html.
SRC=source
NAME=embedName
HEIGHT=height
WIDTH=width>
[parameterName=parameterValue]
[ ... parameterName=parameterValue]
</EMBED>
Implemented in
Navigator 3.0
Tainted?
No
Description
You can reference embedded objects (created with the <EMBED> tag) in 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]
.
Elements in the embeds array may have public callable functions, if they reference a "LiveConnected" plug-in. See Chapter 4, "LiveConnect."
To use the embeds array:
1. document.embeds[index]
index is an integer representing an <EMBED> tag or the name of an embedded object as specified by the NAME attribute.
To obtain the number of <EMBED> tags in a document, use the length property:
2. document.embeds.lengthdocument.embeds.length
.
Use the elements in the embeds array to interact with the plug-in that is displaying the embedded object. If a plug-in is not Java-enabled, you cannot do anything with its element in the embeds array. The fields and methods of the elements in the embeds array vary from plug-in to plug-in; see the documentation supplied by the plug-in manufacturer.
When you use the <EMBED> tag to generate output from a plug-in application, you are not creating a Plugin object. See the Plugin object.
Elements in the embeds array are read-only. For example, the statement document.embeds[0]="myavi.avi"
has no effect.
Properties
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>
navigator.mimeTypes[index].enabledPlugin
Implemented in
Navigator 3.0
Tainted?
No
Description
Use the enabledPlugin property to determine which plug-in is configured for a specific MIME type. Each plug-in may support multiple MIME types, and each MIME type could potentially be supported by multiple plug-ins. However, only one plug-in can be configured for a MIME type. (On Macintosh and Unix, the user can configure the handler for each MIME type; on Windows, the handler is determined at Navigator start-up time.)
The enabledPlugin property is a reference to a Plugin object that represents the plug-in that is configured for the specified MIME type. If the MIME type does not have a plug-in configured, enabledPlugin is null.
Without the enabledPlugin property, you could determine if the user has a particular plug-in installed, if their Navigator can handle a particular MIME type, and if the MIME type is supported by any plug-ins. But you could not determine whether a plug-in is configured for the MIME type. You might need to know this information, for example, so you could dynamically emit an <EMBED> tag on the page if the user has a plug-in configured for the MIME type.
enabledPlugin is a read-only property.
Examples
The following example determines whether the Shockwave plug-in is installed. If it is, a movie is displayed.
// Can we display Shockwave movies?
See also the examples for the MimeType object.
mimetype = navigator.mimeTypes["application/x-director"]
if (mimetype) {
// Yes, so can we display with a plug-in?
plugin = mimetype.enabledPlugin
if (plugin)
// Yes, so show the data in-line
document.writeln("Here\'s a movie: <EMBED SRC=mymovie.dir HEIGHT=100 WIDTH=100>")
else
// No, so provide a link to the data
document.writeln("<A HREF='mymovie.dir>Click here</A> to see a movie.")
} else {
// No, so tell them so
document.writeln("Sorry, can't show you this cool movie.")
} See also
description, type, suffixes properties
formName.encoding
Implemented in
Navigator 2.0
Tainted?
No
Description
The encoding property initially reflects the ENCTYPE attribute of the <FORM> tag; however, setting encoding overrides the ENCTYPE attribute.
You can set the encoding property at any time.
Examples
The following function returns the value of the musicForm encoding property:
function getEncoding() {
return document.musicForm.encoding
} See also
action, method, target properties; Form object
escape("string")
escape("Hello, World")The following example returns "%26":
escape("&")The following example returns "%21%23":
escape("!#")
[objectName.]eval(string)
"3 * x + 2"
, to a variable, and then calling eval at a later point in your script.
var x = 2Example 2. In the following example, the getFieldName(n) function returns the name of the nth form element as a string. The first statement assigns the string value of the third form element to the variable field. The second statement uses eval to display the value of the form element.
var y = 39
var z = "42"
document.write(eval("x + y + 1"), "<BR>")
document.write(eval(z), "<BR>")
var field = getFieldName(3)Example 3. The following example uses eval to evaluate the string str. This string consists of JavaScript statements that open an Alert dialog box and assigns z a value of 42 if x is five, and assigns zero to z otherwise. When the second statement is executed, eval will cause these statements to be performed, and it will also evaluate the set of statements and return the value that is assigned to z.
document.write("The field named ", field, " has value of ", eval(field + ".value"))
var str = "if (x == 5) {alert('z is 42'); z = 42;} else z = 0; "Example 4. In the following example, the setValue function uses eval to assign the value of the variable newValue to the text field textObject:
document.write("<P>z is ", eval(str))
function setValue (textObject, newValue) {Example 5. The following example creates breed as a property of the object myDog, and also as a variable. The first write statement uses
eval ("document.forms[0]." + textObject + ".value") = newValue
}
eval('breed')
without specifying an object; the string "breed" is evaluated without regard to any object, and the write method displays "Shepherd", which is the value of the breed variable. The second write statement uses myDog.eval('breed')
which specifies the object myDog; the string "breed" is evaluated with regard to the myDog object, and the write method displays "Lab", which is the value of the breed property of the myDog object.
function Dog(name,breed,color) {Example 6. The following example uses eval within a function that defines an object type, flintstone. The statement
this.name=name
this.breed=breed
this.color=color
}
myDog = new Dog("Gabby")
myDog.breed="Lab"
var breed='Shepherd'
document.write("<P>" + eval('breed'))
document.write("<BR>" + myDog.eval('breed'))
fred = new flintstone("x=42")
creates the object fred with the properties x, y, z, and z2. The write statements display the values of these properties as 42, 43, 44, and 45, respectively.
function flintstone(str) {
this.eval("this."+str)
this.eval("this.y=43")
this.z=44
this["z2"] = 45
}
fred = new flintstone("x=42")
document.write("<BR>fred.x is " + fred.x)
document.write("<BR>fred.y is " + fred.y)
document.write("<BR>fred.z is " + fred.z)
document.write("<BR>fred.z2 is " + fred.z2)
Math.exp(number)
Implemented in
Navigator 2.0
Examples
The following function returns the exp value of the variable x:
function getExp(x) {
If you pass getExp the value 1, it returns 2.718281828459045.
return Math.exp(x)
} See also
E, log, pow methods