Javascript window location object properties contain information about the current URL. For example” location.pathname” returns “/subdirectory/search.”
Example URL: http://www.domain.com/subdirectory/search?filter=a#somewhere
Javascript Window Location Object Properties
Property | Description | Returns |
---|---|---|
hash | Returns the anchor portion of a URL | #somewhere |
host | Returns the hostname and port of a URL | www.domain.com (will include port if one exists) |
hostname | Returns the hostname of a URL | www.domain.com |
href | Returns the entire URL | http://www.domain.com/subdirectory/search?filter=a#somewhere |
pathname | Returns the path name of a URL | /subdirectory/search |
port | Returns the port number the server uses for a URL | (empty string) |
protocol | Returns the protocol of a URL | http: |
search | Returns 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: " + location.host + "\n" +
"hostname: " + location.hostname + "\n" +
"href: " + location.href + "\n" +
"pathname: " + location.pathname + "\n" +
"port: " + location.port + "\n" +
"protocol: " + location.protocol + "\n" +
"search: " + location.search );
</script>