Location pathname Property - Javascript Browser Object Model

Javascript examples for Browser Object Model:Location

Description

The pathname property sets or gets the pathname of a URL.

Set the pathname property with the following Values

Value Type Description
path String Sets the pathname of the URL

Return Value

A String, representing the pathname

The following code shows how to return the path name of the current URL:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*w ww.  jav  a  2  s.com*/
    var x = location.pathname;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials