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 324 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
You drown not by falling in the river, but by staying submerged.