get url javascript

JavaScript
var currentUrl = window.location.href; document.getElementById("demo").innerHTML =
"Page location is " + window.location.href;

 window.location.hostnameconsole.log(window.location.origin);
Source

Also in JavaScript: