The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Displaying Information in the Browser

JScript displays information in a browser by using the write method of the browser's document object. It can also display information in forms within a browser and in alert, prompt, and confirm message boxes. For more information, see Using Message Boxes.


For additional information about how to write scripts that run on a client computer in a Web browser, see JScript (Windows Script Technologies).

The most common way to display information is the write method of the document object. It takes one argument, a string, which it displays in the browser. The string can be either plain text or HTML.

Strings can be enclosed in either single or double quotation marks, so you can quote something that contains quotation marks or apostrophes.

The following example illustrates the use of the write method.

document.write("Pi is approximately equal to " + Math.PI);
// New line.
document.write("<br />");
document.write("This is an engraving of a horse.");
// New line.
document.write("<br />");
document.write('<IMG SRC="help.png">');

When you call the write method, the document is opened and cleared if it is not being opened and parsed when the write method is called. This causes potentially unexpected results. The following example shows a script that is intended to display the time every 5 seconds, but it cannot do so after the first time because it clears itself in the process.


<script language="JScript" type="text/jscript">
    function ShowTime()
        var dt = new Date();
        window.setTimeout("ShowTime();", 5000);

<script language="JScript" type="text/jscript">


If you use the alert method of the window object instead of document.write, the script works.

        window.setTimeout("ShowTime();", 5000);
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2015 Microsoft