Javascript examples for Browser Object Model:Location
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 |
A String, representing the pathname
The following code shows how to return the path name of the current URL:
<!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>