javascript get current url
snippet in javascript

javascript get current url

user4130

var currentUrl = window.location.href;

get actual url in variable

user1393

var currentLocation = window.location;

get url javascript

user7743


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

 

javascript get domain

user888

window.location.hostname

get the current url javascript

user6495

window.location.pathname; // Returns path only (/path/example.html)
window.location.href;     // Returns full URL (https://example.com/path/example.html)
window.location.origin;   // Returns base URL (https://example.com)