Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / Javascript

Get current page URL using JavaScript

4.00/5 (4 votes)
24 Nov 2012CPOL 62K  
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:

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. 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)