Javascript window location object properties contain information about the current URL. For example” location.pathname” returns “/subdirectory/search.”

Example URL:

Javascript Window Location Object Properties

hashReturns the anchor portion of a URL#somewhere
hostReturns the hostname and port of a (will include port if one exists)
hostnameReturns the hostname of a
hrefReturns the entire URL
pathnameReturns the path name of a URL/subdirectory/search
portReturns the port number the server uses for a URL(empty string)
protocolReturns the protocol of a URLhttp:
searchReturns the query portion of a URL?filter=a

Javascript Window Location Object Properties Alert

   <script type="text/javascript">
        //note some parts may be blank depending on your URL
        alert("hash: " + location.hash + "\n" +
        "host: " + + "\n" +
        "hostname: " + location.hostname + "\n" +
        "href: " + location.href + "\n" +
        "pathname: " + location.pathname + "\n" +
        "port: " + location.port + "\n" +
        "protocol: " + location.protocol + "\n" +
        "search: " + );  


Please enter your comment!
Please enter your name here