get the current url in javascript

this will get the current address add it to a variable and show it on the result element
function get_url() {
  var window_location = window.location.href;
  document.getElementById("loc_res").innerHTML = window_location ;


<div id='loc_res' class='alert alert-primary'>...</div><p>
<button onclick='get_url();' class='btn btn-primary'>Get URL</button>



Other Items in javascript
Page Views

This page has been viewed 253 times.

Search Code
Search Code by entering your search text above.

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.


Random Quote
1. Show your work to the world instead of keeping in your head💆. 2. Do the work consistently👌 3. Respect your work🥰 4. Don't postpone your work 5. Make mistakes 🔥🔥🔥