If you want to get the current URL, then call href
property of the Location
object. The URL returns by location.href
property includes the following:
let url = location.href; console.log(url); //https://www.tutorialsandyou.com/javascript/how-to-get-the-current-url-in-javascript-132.html url = window.location.href; console.log(url); //https://www.tutorialsandyou.com/javascript/how-to-get-the-current-url-in-javascript-132.html