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

Chapter 20. Manipulating Windows and Fra... > Filling Your Windows II: The documen...

Filling Your Windows II: The document Object

A second way of specifying content for new windows—or for your original Web browser window, for that matter—is by using methods of the document object. The following document object methods are used to create content within an HTML document:

  • document.open()— The open() method is used to open the document for writing. If the method is used within an existing Web page, the content created will replace the current contents.

  • document.write() or document.writeln()— Each of these methods is used to write HTML code into the currently opened document. If these statements are encountered while the current document is being loaded—in the following example, the document is already open—the content they generate will be included along with the other contents of the page.

    If these methods are used after the current document has been opened, but without a preceding document.open() method, they will generate an error. If the document.open() method is used, all the content generated will replace the current contents.

    The only difference between the write() and writeln() method is that the writeln() method includes a new line after the content. This does not affect the HTML generated, but makes it easier to view.

  • document.close()— This method closes and causes to be displayed a document opened using the document.open() method.



Not a subscriber?

Start A Free Trial

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