• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 16. Dynamic HTML: Changing Web P... > Self-Modifying Pages Using document....

Self-Modifying Pages Using document.write

We’ve used the document.write method (see in Table 9.5) to change documents on-the-fly throughout this book, but it’s important to include it in our Dynamic HTML chapters. This method is limited in precision, because it’s hard to specify exactly when the writing should start to a document. (Note that relying on a certain loading order of elements to estimate when the <SCRIPT> element containing the document.write method will execute is not reliable.) As a result, programmers usually use document.write only when a document is loading or when they’re creating a new document. Here’s an example from Chapter 9, “Using the document and body Objects,” that writes different HTML to a document, letting users indicate with a confirm dialog box whether they want to see the large image or a smaller one:

<HTML> 
    <HEAD> 
        <TITLE> 
            Self-modifying Web Pages 
        </TITLE> 
    </HEAD> 

    <BODY> 
        <H1>Self-modifying Web Pages</H1> 
        <SCRIPT LANGUAGE="JavaScript"> 
            <!--
            if(confirm("Do you want a graphics intensive page?")) {
					document.write("<BR><IMG WIDTH='2048' HEIGHT='2048' " +
					"SRC='gif/bigimage.jpg'></IMG>")
					}
					else {
					document.write("<BR><IMG WIDTH='100' HEIGHT='100' " +
					"SRC='gif/smallimage.jpg'></IMG>")
					} 
            // --> 
        </SCRIPT> 
    </BODY> 
</HTML> 

					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint