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.

Recent JavaScript Tutorials

Javascript FSO ShortPath property

Javascript FileSystemObject (FSO) provides a ShortPath property that can be accessed using the folder object or file object returned by the GetFolder or GetFile method.

Javascript FSO Path Property

Javascript FileSystemObject (FSO) provides the Path property that can be accessed through the file object or folder object returned by the GetFile or GelFolder method

Javascript FSO Type property

Javascript FileSystemObject (FSO) provides a Type property that can be accessed through file object or folder object returned by the GetFile or GetFolder method

Javascript FSO ShortName property

Javascript FileSystemObject (FSO) provides a ShortName property that can be accessed using the folder object or file object returned by the GetFolder or GetFile method.

Javascript FSO Name Property

Javascript FileSystemObject (FSO) provides a Name property that can be accessed using file object or folder object.