Click here to Skip to main content
Click here to Skip to main content

Get current page URL using JavaScript

By , 24 Nov 2012
 

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)

About the Author

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

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 1memberpepri26 Nov '12 - 12:14 
GeneralWonderfulmemberRahulKhadikar25 Nov '12 - 21:08 
GeneralMy vote of 5membervikram190725 Nov '12 - 17:56 
GeneralMy vote of 5memberJrPacheco24 Nov '12 - 5:47 

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

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