Skip to main content

Posts

Showing posts from February, 2013

How to get current page URL in JavaScript/JQuery

Sometimes, we need to access the current URL in our JavaScript/JQuery code. We need to get any query string value or we need to check URL for any specific value/sub domain. There are a lot of situations when we want to fetch current URL in our code. There are several ways to do this. Here, I am discussing some of them. I will use the below URL to test the output. http://www.mysite.com/abc.aspx?qs1=test1&qs2=test2 Using classical JavaScript: Property            Result ================================================================================= window.location                     http://www.mysite.com/abc.aspx?qs1=test1&qs2=test2 window.location.href              http://www.mysite.com/abc.aspx?qs1=test1&qs2=test2 window.location.pathname   ...