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)
month, day, year, hours, minutes, and seconds are string values for form 2 of the syntax. for forms 3 and 4, they are integer values.
propertyname is one of the properties listed below.
methodname is one of the methods listed below.
form 1 of the syntax creates today's date and time. if you omit hours, minutes, or seconds from form 2 or 4 of the syntax, the value will be set to zero.
the way javascript handles dates is very similar to the way java handles dates: both languages have many of the same date methods, and both store dates internally as the number of milliseconds since january 1, 1970 00:00:00. dates prior to 1970 are not allowed.
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
radioname is the value of the name attribute of a radio object.
index is an integer representing a radio button in a radio object.
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.
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
index is an integer representing an option in a select object.
optionname is the name of a select object option created using the option() constructor.
you can set the defaultselected property at any time. the display of the select object does not update when you set the defaultselected property, only when you set the selected or selectedindex properties.
a select object created without the multiple attribute can have only one option selected by default. when you set defaultselected in such an object, any previous default selections, including defaults set with the selected attribute, are cleared. if you set defaultselected in a select object created with the multiple attribute, previous default selections are not affected.
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.
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
textname is either the value of the name attribute of a text object or an element in the elements array.
textareaname is either the value of the name attribute of a textarea object or an element in the elements array.
implemented in
navigator 2.0
tainted?
yes
description
the initial value of defaultvalue differs for each object:
you can set the defaultvalue property at any time. the display of the related object does not update when you set the defaultvalue property, only when you set the value property.
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
index2 is either an integer representing a plug-in installed on the client or a string containing the name of a plugin object (from the name property).
for plugin objects, the description property is a description of the plug-in. the description is supplied by the plug-in itself.
description is a read-only property.
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>
bgcolor, text, link, alink, and vlink are color specifications expressed as a hexadecimal rgb triplet (in the format "rrggbb" or "#rrggbb") or as one of the string literals listed in "color values".
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.
property of
window object
you can load a new document by using the window.location object.
you can clear the document pane (and remove the text, form elements, and so on so they do not redisplay) by using
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
.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.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".
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
index is an integer representing an object on a form or the name of an object as specified by the name attribute.
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]
.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[0]="music"
has no effect.
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>
name=embedname specifies the name of the embedded object in the document. you can use this name when indexing the embeds array.
height=height specifies the height of the applet in pixels within the browser window.
width=width specifies the width of the applet in pixels within the browser window.
parametername=parametervalue specifies the name and value of a parameter to pass to the embedded object's plug-in.
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]
.
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.
2. document.embeds.lengthdocument.embeds.length
.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.)
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.
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)
string is any string representing a javascript expression, statement, or sequence of statements. the expression can include variables and properties of existing objects.
navigator 3.0: a method of every object
if you construct an arithmetic expression as a string, you can use eval to evaluate it at a later time. for example, suppose you have a variable x. you can postpone evaluation of an expression involving x by assigning the string value of the expression, say
"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