Click here to Skip to main content
11,634,796 members (67,563 online)
Click here to Skip to main content

Get current page URL using JavaScript

, 24 Nov 2012 CPOL 40.6K 5
Rate this:
Please Sign up or sign in to vote.
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. 

License

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

Share

About the Author

Samrat Banerjee
Software Developer (Senior) Viscus Infotech Ltd. [India]
India India
Hi, I am Samrat Banerjee from India.
I am a Software Engineer working in .net platform.
I love to explore new technologies.

You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 1 Pin
pepri26-Nov-12 12:14
memberpepri26-Nov-12 12:14 
GeneralWonderful Pin
RahulKhadikar25-Nov-12 21:08
memberRahulKhadikar25-Nov-12 21:08 
GeneralMy vote of 5 Pin
vikram190725-Nov-12 17:56
membervikram190725-Nov-12 17:56 
GeneralMy vote of 5 Pin
JrPacheco24-Nov-12 5:47
memberJrPacheco24-Nov-12 5:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150728.1 | Last Updated 24 Nov 2012
Article Copyright 2012 by Samrat Banerjee
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid