Javascript Location object

The client – side Javascript/JScript/ECMAScript model has a rich set of methods and properties related to the Page and Window objects. One of the most useful of these is the ability to parse the various components of the URL. But before we look at that, this might be a good time to review the methods and properties of the location object.
The Location object is part of a Window object and is accessed through the window.location property. It contains the complete URL of a given Window object, or, if none is specified, of the current Window object.

The invocation of setting the window.location property immediately instructs the browser to perform the requested navigation.
PROPERTIES:

  • hash Property:  The hash property is a string beginning with a hash (#), that specifies an anchor name in an HTTP URL
  • host Property: The host property is a string comprising of the hostname and port strings.
  • hostname Property:  The hostname property specifies the server name, subdomain and domain name (or IP address) of a URL.
  • href Property : The href property is a string specifying the entire URL, and of which all other Link properties are substrings.
  • pathname Property: The pathname property is a string portion of a URL specifying how a particular resource can be accessed.
  • port Property:  The port property is a string specifying the communications port that the server uses.
  • protocol Property:  The protocol property is the string at the beginning of a URL, up to and including the first colon ( : ), which specifies the method of access to the URL, e.g. “http:”, “mailto:”, “ftp:”, etc.
  • search Property:  The search property is a string beginning with a question mark that specifies any query information in an HTTP URL.

METHODS

  • reload Method: The reload method forces a reload of the window’s current document, i.e. the one contained in the Location.href property (location.reload([forceGet])) . For example, onClick = ” window.location.reload(true)” would force a GET reload, ignoring the fact that the document may already be in the cache.
  • replace Method: The replace method replaces the current History entry with the specified URL. After calling the replace method, you cannot navigate back to the previous URL using the browser’s Back button.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s