The pathname
property sets or gets the path of a URL.
pathname |
Yes | Yes | Yes | Yes | Yes |
Return the pathname property.
var v = location.pathname
Set the pathname property.
location.pathname=path
Value | Type | Description |
---|---|---|
path | String | Set the URL path |
A String type value representing the path
The following code shows how to get the path of the current URL.
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<!-- w w w.j a v a 2 s . co m-->
<p id="demo"></p>
<script>
function myFunction() {
var x = location.pathname;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: