I have some custom javascript functions that are included on all of my web pages; however, a few functions are only intended for the home page. So I decided to use the “window.location” object to determine if the site URL is in fact the home. See example below:
if(window.location==”http://domain.com/”){
// run home page functions
}
Here are a few other helpful JavaScript objects that expose site locations:
- hash: Returns the anchor portion of a URL
- host: Returns the hostname and port of a URL
- hostname: Returns the hostname of a URL
- href: Returns the entire URL
- pathname: Returns the path name of a URL
- port: Returns the port number the server uses for a URL
- protocol: Returns the protocol of a URL
- search: Returns the query portion of a URL



