The document object provides five methods, through which you can manipulate its contents.
Writes the string variable to the current document. For example:
Document.write "This is an example of the write method"
The string gets inserted in the current document at the current position, and it doesn't appear until the close method is called.
Places the string variable into the current document with a new-line character appended to the end. The new-line character is ignored by the browser, so the writeLn method operates practically the same as the write method.
Opens the document for output. The current contents of the document are cleared, and new strings can be placed in the document with the write and writeLn methods.
Updates the screen to display all of the strings written after the last open method call.
Clears the contents of the document.
The common sequence of methods used to place data in the current document is
Document.open Document.write "This is an example of write method" Document.close
Instead of using a string enclosed in quotes, you can write a variable to the document, which could be the result of a calculation or a string that's calculated on the fly at the client's side (an expression that depends on the current day, for instance). The most interesting aspect of the write and writeLn methods is that their argument may also contain HTML tags. For instance, the statements
Document.open Document.write "<h2 align="center">Title 1</h2>" Document.write "<h3 align="center">Title 2</h3>" Document.close
will cause title 1 and title 2 headings to appear and be centered on the browser's window.
The history object is an invisible object that provides methods for navigating through the document's history. It provides the functionality of the browser's navigational buttons, with the added benefit that you can access this functionality through programming. The methods of history object are as follows:
Moves back in the history list by n steps, as if the user has clicked on the browser's Back button n times. The following statement returns you to the most recently visited URL:
window.history.back 1
Moves forward in the history list by n steps, as if the user has clicked on the browser's Forward button n times.
Moves to the nth item in the history list. The statement
window.history.go 1
will take you to the first URL in the list.
The history object also provides a property, the length property. This property represents the number of URLs in the history list.
Go To Page: 1 2
| Here's the follow-up discussion on this article: | View all related messages |
For a complete listing of article comments, questions, and other discussions related to Maxim Karetnikov's VB Script topic, please visit the Discussions page.