65.9K
CodeProject is changing. Read more.
Home

Get current page URL using JavaScript

starIconstarIconstarIconstarIconemptyStarIcon

4.00/5 (4 votes)

Nov 24, 2012

CPOL
viewsIcon

61988

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.