Click here to Skip to main content
13,052,956 members (78,986 online)
Click here to Skip to main content
Add your own
alternative version


5 bookmarked
Posted 24 Nov 2012

Get current page URL using JavaScript

, 24 Nov 2012
Rate this:
Please Sign up or sign in to vote.
Get current page URL on client side.


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. 


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)
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    Praise Praise    Rant Rant    Admin Admin   

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

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