How to Get the current Page URL with JavaScript

To get the current web page URL of your browser you need to grab the window.location.href property.

Type the following code in your browser console and hit enter:


var currentURL = window.location.href;

currentURL();
Gif video. Getting the window URL via the Chrome Console
If you’re using an online editor like CodePen, you need to use console.log(currentURL) to return the result.

Has this been helpful to you?

You can support my work by sharing this article with others, or perhaps buy me a cup of coffee 😊

Kofi

Share & Discuss on