Javascript location pathname property sets or returns the path of the current URL except hostname or domain name. Location pathname property does not return hostname and query string variables along with pathname; it returns only string having directory names and current webpage name. Also location.pathname property does not return the protocol name also used to access the current URL.
Syntax for Javascript Location Pathname Property
location.pathname
or
window.location.path
Both syntax with or without window object returns the same value of pathname for the current URL.
Following syntax shows how to set the value of location pathname property:
location.pathname = "value";
Example of Javascript Location Pathname Property
<script type="text/javascript" language="javascript">
function locationPathname() {
alert(window.location.pathname);
}
</script>
Assume that the current URL is http://www.ezineasp.net/post/Javascript-Window-Location-Object.aspx. Then above example will show the alert message box with value /post/Javascript-Window-Location-Object.aspx
Continue to next tutorial: Javascript Location Search with Examples to learn how to retrieve the QueryString variables from the current URL.