Saturday, September 21, 2013

Getting Page URL using Javascript

Getting Page URLs using Javascript is very useful in real life projects, it's been used by Facebook, Twitter for their share/tweet buttons, because when we click on the share button then we get the URL of the page we are browsing, and that's done using Javascript.

var url= "";
if (typeof this.href === "undefined") {
    url = document.location.toString().toLowerCase();
else {
    url= this.href.toString().toLowerCase();
Liked the post ? subscribe us with your email to get upcoming tutorials directly in your inbox:


  1. You shouldn't use .toLowerCase() for URLs. Linux and other Unix based web servers are case sensitive after the domain name, so is not the same as Real world current example: works, but gives their "not found" page.

    1. That's a point, case sensitiveness can effect a lot.


Your Comment Will Be Visible After Approval, Thanks !