Getting Current Location Details
Finding the Current Hash
The location.hash value returns the current hash, if any, that the browser is using. This is useful when you are displaying a web page with multiple hash anchors. The hash provides a context to the location on the page the user actually clicked.
Getting the Host Name
The location.hostname value returns the domain name of the server that sent the page to the user. This is just the portion after the protocol but before the port number or path. This allows you to determine which server to send AJAX requests back to. Often, multiple servers may handle the web site, but you may want to interact only with the server that served the web page in the first place.
Looking at the File Path
The location.pathname returns the path that the page was loaded from on the server. The pathname also provides a context as to what page the user is looking at.
Getting the Query String
Determining If the Page Is Viewed on a Secure Protocol
The easiest way to determine if a page is being viewed from a secured location on the server is to look at the location.protocol value. This value will be http on regular requests or https on secure requests.