KOMPX.COM or COMPMISCELLANEA.COM   

Get the current URL in JavaScript

Getting the full URL of the current page in Vanilla JavaScript:

HTML code:


<div class="example">
</div>

JavaScript code:


<script>
// Getting the full URL of the current page
var currentURL = window.location.href;

// Printing the result
document.querySelector('.example').textContent = currentURL;
</script>

Links

  1. location: href property: developer.mozilla.org/en-US/docs/Web/API/Location/href
  2. JavaScript Window Location: www.w3schools.com/js/js_window_location.asp
Browser support
Windows
Internet Explorer 4.0+
Edge 12.0+
Firefox 1.0+
Google Chrome 1.0+
Opera 3.0+
Safari 3.1+
SeaMonkey 1.0+
Mozilla 0.6+
Netscape 2.0+
Linux
Firefox 1.0+
Google Chrome / Chromium
Opera 5.0+
SeaMonkey 1.0+
Mozilla 0.6+
Netscape 2.0+
Hv3
iOS
Safari 1.0+
Android
Samsung Internet 1.0+
Chrome 18.0+
Firefox 4.0+
Opera 12.1+
More