Get current page path name in JavaScript

Description

The following code shows how to get current page path name.

Example


<!--from  www .  j a  v a 2  s.  com-->
<!DOCTYPE HTML>
<html>
<body>
<script>
document.writeln("pathname: " + document.location.pathname);
</script>
</body>
</html>

Click to view the demo

The code above generates the following result.

Get current page path name in JavaScript