Current URL Display
Let users know where they are. This script accesses the window.location object to retrieve and print the full URL of the current page.
You are currently at:
Loading...
Copy the Script
<p>Current Page: <span id="loc"></span></p>
<script>
document.getElementById("loc").innerHTML = window.location.href;
</script>
Frequently Asked Questions
Yes. `window.location.href` returns the full string, including `?id=123` and `#hash` tags.
Yes. Use `window.location.hostname` to get just 'www.yoursite.com', or `window.location.pathname` for just the file path.
Yes, parsing the URL string is exactly how automatic breadcrumb scripts (like the one in this silo) work.