Visit Mozilla.org

DOM:document.location

From MDC

« Gecko DOM Reference

Contents

[edit] Summary

Returns a Location object, which contains information about the URL of the document and provides methods for changing that URL. In Gecko browsers you can also assign to this property to load another URL.

For details, refer to window.location.

[edit] Syntax

// Get the location object
var locationObj = document.location;

// Set the value of the location object (see Notes section)
document.location = 'http://www.mozilla.org';

[edit] Example

dump(document.location); 
// Prints a string like
// "http://www.example.com/juicybits.html" to the console

[edit] Notes

Location objects have a toString method returning the current URL. You can also assign a string to document.location. This means that you can work with document.location as if it were a string in most cases. Sometimes, for example when you need to call a String method on it, you have to explicitly call toString:

alert(document.location.toString().charAt(17))

document.location was originally a read-only property, although Gecko browsers allow you to assign to it as well. For cross-browser safety, use window.location instead.

To retrieve just the URL as a string, the read-only document.URL property can be used.

[edit] Specification

DOM Level 0. Not part of any standard.