I spent a lot of time searching for jQuery code snippet that could fetch the current url path from where the jQuery file is executed. But jQuery method $(location).attr('protocol') + "//" + $(location).attr('host'); fetches the url of the current page.