taint(dataelementname)
use taint to mark data that otherwise is not tainted.
in some cases, control flow rather than data flow carries tainted information. in these cases, taint is added to the script's window. you can add taint to the script's window by calling taint with no arguments. see "tainting that results from conditional statements".
taint does not modify its argument; instead, it returns a marked copy of the value, or, for objects, an unmarked reference to the value.
examples
the following statement adds taint to a property so that a script cannot send it to another server without the end user's permission:taintedstatus=taint(window.defaultstatus)
// taintedstatus now cannot be sent in a url or form post without
// the end user's permission
see also
domain property; taintenabled method; untaint function; "using data tainting for security"
navigator.taintenabled()
implemented in
navigator 3.0
description
tainting prevents other scripts from passing information that should be secure and private, such as directory structures or user session history. javascript cannot pass tainted values on to any server without the end user's permission.
examples
the following code executes function1 if data tainting is enabled; otherwise it executes function2.if (navigator.taintenabled()) {
function1()
}
else function2()
see also
domain property; taint, untaint functions; "using data tainting for security"
math.tan(number)
implemented in
navigator 2.0
description
the tan method returns a numeric value that represents the tangent of the angle.
examples
the following function returns the tangent of the variable x:function gettan(x) {
if you pass gettan the value math.pi/4, it returns 0.9999999999999999.
return math.tan(x)
}
see also
acos, asin, atan, atan2, cos, sin methods
1. formname.target
2. links[index].target
3. areaname.target
index is an integer representing a link object or the name of a link object as specified by the name attribute.
areaname is the value of the name attribute of an area object.
you can set target using a string, if the string represents a window name. the target property cannot be assigned the value of a javascript expression or variable.
you can set the target property at any time.
document.musicinfo.target="msgwindow"
<input
type="text"
name="textname"
value="textvalue"
size=integer
[onblur="handlertext"]
[onchange="handlertext"]
[onfocus="handlertext"]
[onselect="handlertext"]>
value="textvalue" specifies the initial value of the text object. you can access this value using the defaultvalue property.
size=integer specifies the number of characters the text object can accommodate without scrolling.
1. textname.propertyname
2. textname.methodname(parameters)
3. formname.elements[index].propertyname
4. formname.elements[index].methodname(parameters)
formname is either the value of the name attribute of a form object or an element in the forms array.
index is an integer representing a text object on a form or the name of a text object as specified by the name attribute.
propertyname is one of the properties listed below.
methodname is one of the methods listed below.
a text object is a form element and must be defined within a <form> tag.
text objects can be updated (redrawn) dynamically by setting the value property (this.value).
if a form contains only one element, a text object, then when the user enters a value and presses return, the form submits. (this is a standard html feature.)
methods
the text object has the following methods:
|
|
<b>last name:</b> <input type="text" name="last_name" value="" size=25>example 2. the following example creates two text objects on a form. each object has a default value. the city object has an onfocus event handler that selects all the text in the field when the user tabs to that field. the state object has an onchange event handler that forces the value to uppercase.
<form name="form1">see also the examples for the onblur, onchange, onfocus, and onselect event handlers.
<br><b>city: </b><input type="text" name="city" value="anchorage"
size="20" onfocus="this.select()">
<b>state: </b><input type="text" name="state" value="ak" size="2"
onchange="this.value=this.value.touppercase()">
</form>
see also
fileupload object, form object, password object, string object, textarea object
1. selectname.options[index].text
2. optionname.text
index is an integer representing an option in a select object.
optionname is the name of a select object option created using the option() constructor.
you can set the text property at any time and the text displayed by the option in the select object changes.
function getchoice() {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].selected == true) {
return document.musicform.musictype.options[i].text
}
}
return null
}
<select name="musictype">
<option selected> r&b
<option> jazz
<option> blues
<option> new age
</select>
<textarea
name="textareaname"
rows="integer"
cols="integer"
[onblur="handlertext"]
[onchange="handlertext"]
[onfocus="handlertext"]
[onselect="handlertext"]>
texttodisplay
</textarea>
rows="integer" and cols="integer" define the physical size of the displayed input field in numbers of characters.
texttodisplay specifies the initial value of the textarea object. a textarea allows only ascii text, and new lines are respected. you can access this value using the defaultvalue property.
1. textareaname.propertyname
2. textareaname.methodname(parameters)
3. formname.elements[index].propertyname
4. formname.elements[index].methodname(parameters)
formname is either the value of the name attribute of a form object or an element in the forms array.
index is an integer representing a textarea object on a form or the name of a textarea object as specified by the name attribute.
propertyname is one of the properties listed below.
methodname is one of the methods listed below.
a textarea object is a form element and must be defined within a <form> tag.
textarea objects can be updated (redrawn) dynamically by setting the value property (this.value).
to begin a new line in a textarea object, you can use a newline character. although this character varies from platform to platform (unix is \n, windows is \r, and macintosh is \n), javascript checks for all newline characters before setting a string-valued property and translates them as needed for the user's platform. you could also enter a newline character programmatically--one way is to test the appversion property to determine the current platform, then set the newline character accordingly. see the appversion property for an example.
methods
the textarea object has the following methods:
|
|
<b>description:</b>example 2. the following example creates a string variable containing newline two characters for different platforms. when the user clicks the button, the textarea object is populated with the value from the string variable. the result is three lines of text in the textarea object.
<br><textarea name="item_description" rows=6 cols=55>
our storage ottoman provides an attractive way to
store lots of cds and videos--and it's versatile
enough to store other things as well.
it can hold up to 72 cds under the lid and 20 videos
in the drawer below.
</textarea>
<script>see also the examples for the onblur, onchange, onfocus, and onselect event handlers.
mystring="this is line one.\nthis is line two.\rthis is line three."
</script>
<form name="form1">
<input type="button" value="populate the textarea"
onclick="document.form1.textarea1.value=mystring">
<p>
<textarea name="textarea1" rows=6 cols=55></textarea>
see also
form object, password object, string object, text object
document.title
implemented in
navigator 2.0
tainted?
yes
description
the title property is a reflection of the value specified within the <title> and </title> tags. if a document does not have a title, the title property is null.
examples
in the following example, the value of the title property is assigned to a variable called doctitle:var newwindow = window.open("http://home.netscape.com")
var doctitle = newwindow.document.title
dateobjectname.togmtstring()
implemented in
navigator 2.0
description
the exact format of the value returned by togmtstring varies according to the platform.
examples
in the following example, today is a date object:today.togmtstring()
in this example, the togmtstring method converts the date to gmt (utc) using the operating system's time-zone offset and returns a string value that is similar to the following form. the exact format depends on the platform.mon, 18 dec 1995 17:28:35 gmt
see also
tolocalestring method
dateobjectname.tolocalestring()
implemented in
navigator 2.0
description
if you are trying to pass a date using tolocalestring, be aware that different locales assemble the string in different ways. using methods such as gethours, getminutes, and getseconds gives more portable results.
examples
in the following example, today is a date object:today.tolocalestring()
in this example, tolocalestring returns a string value that is similar to the following form. the exact format depends on the platform.12/18/95 17:28:35
see also
togmtstring method
stringname.tolowercase()
implemented in
navigator 2.0
description
the tolowercase method returns the value of stringname converted to lowercase. tolowercase does not affect the value of stringname itself.
examples
the following example displays the lowercase string "alphabet":var uppertext="alphabet"
document.write(uppertext.tolowercase())
see also
touppercase method
1. top.propertyname
2. top.methodname
3. top.framename
4. top.frames[index]
methodname is any method associated with the window object.
framename and frames[index] are ways to refer to frames.
implemented in
navigator 2.0
tainted?
no
description
the top property refers to the top-most window that contains frames or nested framesets. use the top property to refer to this ancestor window. <object objectreference>
where objectreference is an internal reference.
examples
the statement top.close()
closes the top-most ancestor window.top.length
specifies the number of frames contained within the top-most ancestor window. when the top-most ancestor is defined as follows, top.length
returns three:<frameset cols="30%,40%,30%">
the following example sets the background color of a frame called myframe to red. myframe is a child of the top-most ancestor window.
<frame src=child1.htm name="childframe1">
<frame src=child2.htm name="childframe2">
<frame src=child3.htm name="childframe3">
</frameset>top.myframe.document.bgcolor="red"
objectname.tostring()
numberobjectname.tostring([radix])
numberobjectname is the number object to convert to a string.
radix is an integer between 2 and 16 specifying the base to use for representing numeric values.
navigator 3.0: added radix
document.write(thedog)you can use tostring within your own code to convert an object into a string, and you can create your own function to be called in place of the default tostring method.
document.write("the dog is " + thedog)
sealife.tostring()
returns [object image]
.
<img name="sealife" src="images\seaotter.gif" align="left" vspace="10">
suppose you have an object type dog and you want to create a tostring method for it. the following code defines the dog object type and creates thedog, an object of type dog:
function dog(name,breed,color,sex) {the following code creates objecttostring, the function that will be used in place of the default tostring method. this function generates a string containing each property, of the form "property = value;".
this.name=name
this.breed=breed
this.color=color
this.sex=sex
}
thedog = new dog("gabby","lab","chocolate","girl")
function objecttostring() {the following code assigns the user-defined function to the object's tostring method:
var ret = "object " + this.name + " is ["
for (var prop in this)
ret += " " + prop + " is " + this[prop] + ";"
return ret + "]"
}
dog.prototype.tostring = objecttostringwith the preceding code in place, any time thedog is used in a string context, javascript automatically calls the objecttostring function, which returns the following string:
object gabby is [ name is gabby; breed is lab; color is chocolate; sex is girl; tostring is function objecttostring() { var ret = "object " + this.name + " is ["; for (var prop in this) { ret += " " + prop + " is " + this[prop] + ";"; } return ret + "]"; } ;]
an object's tostring method is usually invoked by javascript, but you can invoke it yourself as follows:
alert(thedog.tostring())
var monthnames = new array("jan","feb","mar","apr")the output is as follows:
document.write("monthnames.tostring() is " + monthnames.tostring())
monthnames.tostring() is jan,feb,mar,apr
flag.tostring
returns "true".
flag = new boolean(true)
document.write("flag.tostring() is " + flag.tostring() + "<br>")
for example, suppose you create the function dog shown in "user-defined tostring methods". any time dog is used in a string context, javascript automatically calls the tostring function, which returns the following string:
function dog(name, breed, color, sex) { this.name = name; this.breed =
breed; this.color = color; this.sex = sex; }
numbers and tostring
you can use tostring on numeric values, but not on numeric literals:// the next two lines are valid
var howmany=10
document.write("howmany.tostring() is " + howmany.tostring() + "<br>")// the next line causes an error
document.write("45.tostring() is " + 45.tostring() + "<br>")
examples
example 1: the location object. the following example prints the string equivalent of the current location.document.write("location.tostring() is " + location.tostring() + "<br>")
the output is as follows:file:///c|/temp/myprog.html
example 2: object with no string value. suppose the following image object named "sealife" exists:<img name="sealife" src="images\seaotter.gif" align="left" vspace="10">
because the image object itself has no string equivalent, sealife.tostring()
will return the following:[object image]
example 3: the radix parameter. the following example prints the string equivalents of the numbers 0 through 9 in decimal and binary.for (x = 0; x < 10; x++) {
the preceding example produces the following output:
document.write("decimal: ", x.tostring(10), " binary: ",
x.tostring(2), "<br>")
}decimal: 0 binary: 0
decimal: 1 binary: 1
decimal: 2 binary: 10
decimal: 3 binary: 11
decimal: 4 binary: 100
decimal: 5 binary: 101
decimal: 6 binary: 110
decimal: 7 binary: 111
decimal: 8 binary: 1000
decimal: 9 binary: 1001
see also
prototype property; valueof method
stringname.touppercase()
implemented in
navigator 2.0
description
the touppercase method returns the value of stringname converted to uppercase. touppercase does not affect the value of stringname itself.
examples
the following example displays the string "alphabet":var lowertext="alphabet"
document.write(lowertext.touppercase())
see also
tolowercase method
1. objectname.type
2. navigator.mimetypes[index].type
index is either an integer representing a mime type supported by the client or a string containing the type of a mimetype object (from the type property).
implemented in
navigator 3.0
tainted?
no
description
for mimetype objects, the type property is a unique string that distinguishes the mime type from all others; for example "video/mpeg" or "audio/x-wav".
type is a read-only property.
examples
the following example writes the value of the type property for every element on a form.for (var i = 0; i < document.form1.elements.length; i++) {
see also the examples for the mimetype object.
document.writeln("<br>type is " + document.form1.elements[i].type)
}
see also
for mimetype objects: description, enabledplugin, suffixes properties
unescape("string")
unescape("%26")the following example returns "!#":
unescape("%21%23")
untaint(dataelementname)
use untaint to clear tainting that marks data that should not to be sent by other scripts to different servers.
a script can untaint only data that originated in that script (that is, only data that has the script's taint code or has the identity (null) taint code). if you use untaint with a data element from another server's script (or any data that you cannot untaint), untaint returns the data without change or error.
in some cases, control flow rather than data flow carries tainted information. in these cases, taint is added to the script's window. you can remove taint from the script's window by calling untaint with no arguments, if the window contains taint only from the current window. see "tainting that results from conditional statements".
untaint does not modify its argument; instead, it returns an unmarked copy of the value, or, for objects, an unmarked reference to the value.
examples
the following statement removes taint from a property so that a script can send it to another server:untaintedstatus=untaint(window.defaultstatus)
// untaintedstatus can now be sent in a url or form post by other
// scripts
see also
domain property; taint function; "using data tainting for security"
document.url
implemented in
navigator 2.0
tainted?
yes
description
url is a read-only property of document containing the full url of the document. url is a string-valued property that usually matches what window.location.href is set to when you load the document, but redirection may change location.href.
examples
the following example displays the url of the current document:document.write("the current url is " + document.url)
see also
href
navigator.useragent
implemented in
navigator 2.0
tainted?
no
description
servers use the value sent in the user-agent header to identify the client.
examples
the following example displays useragent information for the navigator:document.write("the value of navigator.useragent is " +
for navigator 2.0, this displays the following:
navigator.useragent)the value of navigator.useragent is mozilla/2.0 (win16; i)
see also
appcodename, appname, appversion, javaenabled properties
date.utc(year, month, day [, hrs] [, min] [, sec])
month is a month between zero and 11.
date is a day of the month between one and 31.
hrs is hours between zero and 23.
min is minutes between zero and 59.
sec is seconds between zero and 59.
implemented in
navigator 2.0
description
utc takes comma-delimited date parameters and returns the number of milliseconds since january 1, 1970, 00:00:00, universal coordinated time (gmt).date.utc()
, rather than as a method of a date object you created.
examples
the following statement creates a date object using gmt instead of local time:gmtdate = new date(date.utc(96, 11, 1, 0, 0, 0))
see also
parse method
1. objectname.value
2. radioname[index].value
3. selectname.options.[index].value
4. fileuploadname.value
5. optionname.value
radioname is the value of the name attribute of a radio object.
selectname is either the value of the name attribute of a select object or an element in the elements array.
index is an integer representing a radio button in a radio object or an option in a select object.
fileuploadname is either the value of the name attribute of a fileupload object or an element in the elements array.
optionname is the name of a select object option created using the option() constructor.
when a value attribute is not specified in html, the value property differs for each object:
value is a read-only property.
do not confuse the value property with the name property. the name property is not displayed on-screen; it is used to reference the objects programmatically.
you can set the value property at any time.
do not confuse the value property with the selection state of the object or the text that is displayed next to each checkbox and radio button. the checked property determines the selection state of the object, and the defaultchecked property determines the default selection state. the text that is displayed is specified following the <input type="checkbox"> or the <input type="radio"> tag.
value is a read-only property.
you can set the value property at any time. the display of the text and textarea objects updates immediately when you set the value property.
if you programmatically set the value property and then evaluate it, javascript returns the current value. if a user interactively modifies the value in the password field, you cannot evaluate it accurately unless data tainting is enabled. see "using data tainting for security".
select object options
for select object options created using the option() constructor, the value property is a string that initially reflects the value attribute. this value is not displayed onscreen, but is returned to the server if the option is selected. the value of this property can change when a program modifies it.
options array
the value property is a string that initially reflects the value attribute. the value of this property can change when a program modifies it. the value property is not displayed on-screen but is returned to the server if the option is selected.
examples
the following function evaluates the value property of a group of buttons and displays it in the msgwindow window:function valuegetter() {
this example displays the following values:
var msgwindow=window.open("")
msgwindow.document.write("submitbutton.value is " +
document.valuetest.submitbutton.value + "<br>")
msgwindow.document.write("resetbutton.value is " +
document.valuetest.resetbutton.value + "<br>")
msgwindow.document.write("helpbutton.value is " +
document.valuetest.helpbutton.value + "<br>")
msgwindow.document.close()
}query submit
the previous example assumes the buttons have been defined as follows:
reset
help<input type="submit" name="submitbutton">
the following function evaluates the value property of a group of radio buttons and displays it in the msgwindow window:
<input type="reset" name="resetbutton">
<input type="button" name="helpbutton" value="help">function valuegetter() {
this example displays the following values:
var msgwindow=window.open("")
for (var i = 0; i < document.valuetest.radioobj.length; i++) {
msgwindow.document.write
("the value of radioobj[" + i + "] is " +
document.valuetest.radioobj[i].value +"<br>")
}
msgwindow.document.close()
}on
the previous example assumes the buttons have been defined as follows:
on
on
on<br><input type="radio" name="radioobj">r&b
<br><input type="radio" name="radioobj" checked>soul
<br><input type="radio" name="radioobj">rock and roll
<br><input type="radio" name="radioobj">blues
see also
objectname.valueof()
you can use valueof within your own code to convert an object into a primitive value, and you can create your own function to be called in place of the default valueof method.
you rarely need to invoke the valueof method yourself. javascript automatically invokes it when encountering an object where a primitive value is expected.
the valueof method is most useful for the following object types. most other objects have no primitive value.
user-defined valueof methods
you can create a function to be called in place of the default valueof method. the valueof method takes no arguments.mynumbertype.prototype.valueof = new function(functiontext)
with the preceding code in place, any time an object of type mynumbertype is used in a context where it is to be represented as a primitive value, javascript automatically calls the function defined in the preceding code.mynumber.valueof()
tostring vs. valueof for string objects
objects in string contexts convert via the tostring method, which is different from string objects converting to string primitives via valueof. all string objects have a string conversion, if only "[object type]". but many objects do not convert to number, boolean, or function. for information on tostring, see tostring.
see also
parseint function, tostring method; "typeof"
document.vlinkcolor
implemented in
navigator 2.0
tainted?
no
description
the vlinkcolor property is expressed as a hexadecimal rgb triplet or as one of the string literals listed in "color values". this property is the javascript reflection of the vlink attribute of the <body> tag. the default value of this property is set by the user on the colors tab of the preferences dialog box, which is displayed by choosing general preferences from the options menu. you cannot set this property after the html source has been through layout.
if you express the color as a hexadecimal rgb triplet, you must use the format rrggbb. for example, the hexadecimal rgb values for salmon are red=fa, green=80, and blue=72, so the rgb triplet for salmon is "fa8072."
examples
the following example sets the color of visited links to aqua using a string literal:document.vlinkcolor="aqua"
the following example sets the color of active links to aqua using a hexadecimal triplet:document.vlinkcolor="00ffff"
see also
alinkcolor, bgcolor, fgcolor, linkcolor properties
imagename.vspace
implemented in
navigator 3.0
tainted?
no
description
the vspace property reflects the vspace attribute of the <img> tag. for images created with the image() constructor, the value of the vspace property is 0.
examples
see the examples for the height property.
see also
border, height, hspace, width properties
imagename.width
implemented in
navigator 3.0
tainted?
no
description
the width property reflects the width attribute of the <img> tag. for images created with the image() constructor, the value of the width property is the actual, not the displayed, width of the image.
examples
see the examples for the height property.
see also
border, height, hspace, vspace properties
windowvar = window.open("url", "windowname" [,"windowfeatures"])for details on defining a window, see the open (window object) method.
to use a window object's properties and methods:
1. window.propertyname
to define an event handler for a window object, use the <body> or <frameset> tags:
2. window.methodname(parameters)
3. self.propertyname
4. self.methodname(parameters)
5. top.propertyname
6. top.methodname(parameters)
7. parent.propertyname
8. parent.methodname(parameters)
9. windowvar.propertyname
10. windowvar.methodname(parameters)
11. propertyname
12. methodname(parameters)<body
...
[onblur="handlertext"]
[onfocus="handlertext"]
[onload="handlertext"]
[onunload="handlertext"]>
</body>
<frameset
rows="rowheightlist"
cols="columnwidthlist"
[onblur="handlertext"]
[onfocus="handlertext"]
[onload="handlertext"]
[onunload="handlertext"]>
[<frame src="url" name="framename">]
</frameset>
note
on some platforms, placing an onblur or onfocus event handler in a
<frameset> tag has no effect. please see the release notes (after starting
netscape, choose release notes from the help menu).
for information on the <body> and <frameset> tags, see the document and frame objects.
to define an onerror event handler for a window object:
window.onerror=errorhandler
for information on specifying the onerror event handler, see onerror event handler.
parameters
windowvar is the name of a new window. use this variable when referring to a window's properties, methods, and containership.
property of
none
implemented in
the self and window properties are synonyms for the current window, and you can optionally use them to refer to the current window. for example, you can close the current window by calling either
window.close()
or self.close()
. you can use these properties to make your code more readable or to disambiguate the property reference self.status
from a form called status
. see the properties and methods listed below for more examples.the top and parent properties are also synonyms that can be used in place of the window name. top refers to the top-most navigator window, and parent refers to a window containing a frameset. see the top and parent properties.
because the existence of the current window is assumed, you do not have to reference the name of the window when you call its methods and assign its properties. for example,
status="jump to a new location"
is a valid property assignment, and close()
is a valid method call. however, when you open or close a window within an event handler, you must specify window.open()
or window.close()
instead of simply using open()
or close()
. due to the scoping of static objects in javascript, a call to close()
without specifying an object name is equivalent to document.close()
.window.location
instead of simply using location
. due to the scoping of static objects in javascript, a call to location
without specifying an object name is equivalent to document.location
, which is a synonym for document.url
.
properties
the window object has the following properties:
the following objects are also properties of the window object:
|
|
win1.html
, which defines the frames for the first window, contains the following code:
<html>
<head>
<title>window object example: window 1</title>
</head>
<body bgcolor="antiquewhite">
<script>
window2=open("win2.html","secondwindow",
"scrollbars=yes,width=250, height=400")
document.writeln("<b>the first window has no name: "
+ window.name + "</b>")
document.writeln("<br><b>the second window is named: "
+ window2.name + "</b>")
</script>
<form name="form1">
<p><input type="button" value="open a message window"
onclick = "window3=window.open('','messagewindow',
'scrollbars=yes,width=175, height=300')">
<p><input type="button" value="write to the message window"
onclick="window3.document.writeln('hey there');
window3.document.close()">
<p><input type="button" value="close the message window"
onclick="window3.close()">
<p><input type="button" value="close window2"
onclick="window2.close()">
</form>
</body>
</html>
win2.html
, which defines the content for window2, contains the following code:
<html>see also the example for the frame object.
<head>
<title>window object example: window 2</title>
</head>
<body bgcolor="oldlace"
onload="alert('message from ' + window.name + ': hello, world.')"
onunload="alert('message from ' + window.name + ': i\'m closing')">
<b>some numbers</b>
<ul><li>one
<li>two
<li>three
<li>four</ul>
</body>
</html>
see also
document, frame objects
1. window.propertyname
2. window.methodname
propertyname is the length or name property when the calling window refers to a frame object.
methodname is any method associated with the window object.
implemented in
navigator 2.0
tainted?
no
description
the window property refers to the current window or frame.window.name
and self.name
both specify the name of the current frame, but self.name
is easier to understand. <object nameattribute>
where nameattribute is the name attribute if window refers to a frame, or an internal reference if window refers to a window.
examples
in the following example, window.status
is used to set the status property of the current window. this usage disambiguates the status property of the current window from a form called "status" within the current window.<a href=""
onclick="this.href=pickrandomurl()"
onmouseover="window.status='pick a random url' ; return true">
go!</a>
see also
self property
document.write(expression1 [,expression2], ...[,expressionn])
the write method is the same as the writeln method, except the write method does not append a newline character to the end of the output.
use the write method within any <script> tag or within an event handler. event handlers execute after the original document closes, so the write method will implicitly open a new document of mimetype
text/html
if you do not explicitly issue a document.open()
method in the event handler.you can use the write method to generate html and javascript code. however, the html parser reads the generated code as it is being written, so you might have to escape some characters. for example, the following write method generates a comment and writes it to window2:
window2=window.open('','window2')
begincomment="\<!--"
endcomment="--\>"
window2.document.write(begincomment)
window2.document.write(" this some text inside a comment. ")
window2.document.write(endcomment)
to view html code that was generated with javascript write and writeln methods, the user must specify the view-source: protocol. if the user chooses document source or frame source from the view menu, the content displayed is that of the wysiwyg: url. the following example shows a view-source: url:
view-source:wysiwyg://0/file:/c|/temp/genhtml.htmlfor information on specifying the view-source: protocol in the location object, see the location object.
var mystery = "world"in the following example, the write method takes two arguments. the first argument is an assignment expression, and the second argument is a string literal.
// displays hello world testing 123
msgwindow.document.write("hello ", mystery, " testing ", 123)
//displays hello world...in the following example, the write method takes a single argument that is a conditional expression. if the value of the variable age is less than 18, the method displays "minor." if the value of age is greater than or equal to 18, the method displays "adult."
msgwindow.document.write
(mystr = "hello " + "world...")
msgwindow.document.write(status = (age >= 18) ? "adult" : "minor")
document.writeln(expression1 [,expression2], ...[,expressionn])
the writeln method is the same as the write method, except the writeln method appends a newline character to the end of the output. html ignores the newline character, except within certain tags such as <pre>.
use the writeln method within any <script> tag or within an event handler. event handlers execute after the original document closes, so the writeln method will implicitly open a new document of mimetype
text/html
if you do not explicitly issue a document.open()
method in the event handler.