Skip to content

Home

How can I get the current URL in JavaScript?

As mentioned in the Window.location Cheat Sheet, JavaScript provides a number of properties and methods to work with the current URL. Among those, Window.location.href provides the easiest way to get the current URL as a string.

const currentURL = () => window.location.href;

currentURL(); // 'https://www.google.com/'

More like this

Start typing a keyphrase to see matching snippets.