JavaScript window.location.pathname Property
You are Here:
JavaScript window.location.pathname Property
The window.location.pathname
property returns the path of the current page.
Note: The empty string if there is no path.
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<script>
document.write("Page path: "+window.location.pathname);
</script>
</body>
</html>
Syntax
window.location.pathname
Return Value
Value | Explanation |
---|---|
String | Returns a string representing the path of the current page. |
More Examples
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<script>
var txt = ""
txt += "<p>Page location: "+window.location.href+"</p>";
txt += "<p>Page hostname: "+window.location.hostname+"</p>";
txt += "<p>Page path: "+window.location.pathname+"</p>";
txt += "<p>Page protocol: "+window.location.protocol+"</p>";
txt += "<p>Port number: "+window.location.port+"</p>";
document.write(txt);
</script>
</body>
</html>
Reminder
Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.