Skip to content

How to get Current URL in JavaScript

You can use the JavaScript window.location.href property to get the current URL in the browser. The result includes host name, query string, fragment identifier, etc.

The following example will display the current url of the page by calling the method currentURL().

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


See also  How to check if variable is an Array in JavaScript

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.