JavaScript Browser Objects

Accessing browser objects

JavaScript Object Hierarchy

Working with windows using the windows object

window.alert ("This is window alert");
window.confirm ("This is window confirm");
window.prompt ("This is window prompt");

Working with web documents using the document object


Writing Text into a Document

The document.write method writes text to the HTML page. document.writeln adds a newline (\n). HTML will ignore the newline character unless between PRE tags.

The document object also includes open and close methods. These methods open and close streams within a page which allow clearing and then re-writing using write and writeln methods. When the method is used the current document is erased. Note that any write methods are not activated until the document.close method is executed; thus writing the stream to the current page. Note that use of the method can cause the execution of your current web page to stop since its HTML commands are all erased. You can specify a MIME document type in the method. This enables you to create a document of any type; such as images and documents used by plug-in applications. MIME means multipurpose internet mail extensions. An internet standard for document types. Web servers send a MIME type to a browser with documents to tell the browser how to display them. Typical browser documents are HTML (MIME type text/html) and text (MIME type text/plain).

Using objects for links and anchors

One link  Another link

document.links and document.anchors contain arrays of links and anchors (named places within an HTML document which can be jumped to) within a document.

Browser History

The window.history object provides information about the URLs that have been visited before and after the current one. It also includes methods to go to previous or next locations. The history is actually an array. It includes a list of all previous pages visited.

Using the location object to work with URLs

The window.location object stores information about the current URL stored in a window. The following statement loads a URL into the current window.

window.location.href = ""

window.location.reload reloads the current document. window.location.replace replaces the current location with another. This does not affect the history.