Home » Javascript28 January 2011

Javascript: How to get current URL without Query string?

Here is a quick code to get the current URL of a page with Javascript:-

var current_url = location.href;

Here is another way:-

var current_url = document.URL;

Suppose, you have query string in your URL and you only want to get the actual URL without the query string.

Here is the code for this:-

var url = location.href;
var url_parts = url.split(‘?’);
var main_url = url_parts[0];

Hope this helps. Thanks.

Javascript

Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed
  • very basic but helpful JS tips, thank for sharing

  • Vivekrazza

    how can i get java script variable value in php without form.

  • Cool_smartmahmood

    Thanks