Get current page URL using JavaScript





4.00/5 (4 votes)
Get current page URL on client side.
Introduction
In our web application sometimes we require current page URLl on client side, like when we share any script or perform any action according to the page name.
Using the code
Here I am sharing the demo code to get the current page URL using JavaScript:
// Get current page url using JavaScript
var currentPageUrl = "";
if (typeof this.href === "undefined") {
currentPageUrl = document.location.toString().toLowerCase();
}
else {
currentPageUrl = this.href.toString().toLowerCase();
}
Points of Interest
The above code works perfectly with popups also.