home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


JavaScript: The Definitive Guide

Previous Chapter 21
JavaScript Reference
Next
 

Document.URL Property

Name

Document.URL Property---the URL of the current document

Availability

Navigator 2.0; enhanced in Navigator 3.0

Synopsis

document.URL

Description

URL is a read-only string property that contains the complete URL of the current document.

document.URL is usually equal to window.location.href for the window that contains document. These two are not always equal, however, because the Document.URL property may be modified through URL redirection--Window.location contains the requested URL, and Document.URL specifies the actual URL where it was found.

The Document.location property is a synonym for the Document.URL property. The URL property is the preferred one, because it is less likely to be confused with the Window object's location property. Note, however, that in Navigator 2.0, the URL property does not appear in for/in loops run over Document objects. Also, the URL property is not supported by Internet Explorer 3.0.

Usage

Some web authors like to include the URL of a document somewhere within the document, so that, for example, if the document is cut-and-pasted to a file, or printed out, there will still be a reference to where it can be found online. The following script, when appended to a document will automatically add the document's URL. (Unfortunately, in Netscape 2.0, text such as this generated by JavaScript won't appear in printouts, which defeats an important purpose of including the location in the first place.)

<script>
document.write('<P><HR><SMALL><I>URL: ' + document.URL
    + '</I></SMALL>');
</script>


Previous Home Next
Document.title Book Index Document.vlinkColor

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell