Home » Javascript

Javascript: How to get current URL without Query string?

28 January 2011 Share/Bookmark

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.

From Mukesh Chapagain's Blog, post Javascript: How to get current URL without Query string?

email

php magento mukesh chapagain

Get New Post by Email
RSS Feed Subscribe RSS Feed
  • http://www.javascriptbank.com/ajax-page-content-loader.html AJAX Content Loader

    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