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?
Let me know in the comments!

Or share it with your friends :-)


No comments to display.