Javascript Browser Location pathname Property get

Introduction

Return the path name of the current URL:

var x = location.pathname;

Click the button to display the path name of the current URL.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {/*from  ww w . ja va2 s  .  c  om*/
  var x = location.pathname;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

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

Property Values

Value Type Description
path String Specifies the pathname of the URL

The pathname property returns a String representing the pathname.




PreviousNext

Related