get the current url in javascript

this will get the current address add it to a variable and show it on the result element

Demo

function get_url() {
  var window_location = window.location.href;
  console.log(window.location.href);
  document.getElementById("loc_res").innerHTML = window_location ;
}

HTML

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

Result

...

Other Items in javascript
Page Views

This page has been viewed 59 times.

Search Code
Search Code by entering your search text above.
Welcome

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.

❤👩‍💻🕹