• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

The location Object

The location object holds information about the location of the current web page, such as its URL, the domain name, path, server port, and more. This object even enables you to navigate to a new URL just by assigning that URL to the location object’s href property—or, in most browsers, even to the location object itself (like this, window.location = "http://www.w3.org").

The location object not only holds the current location in the href property, but also lets you dissect that URL in a handy way, using several properties such as hostname (the www.name.com part), host (the same as the hostname property with a port number appended if there is one—for example, in the URL http://www.name.com:80/index.html, the hostname is www.name.com:80), href (the current URL in full), hash (the part of the URL following the hash mark, #, in the URL if there is one), and pathname (the file name or path specified in the URL). For example, take a look at this URL that discusses the changes in the HTML 4.01 W3C specification:


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint