how to remove query string from url?

Today, We want to share with you how to remove query string from url?.In this post we will show you remove specific parameter from url jquery, hear for how to remove query string from url after page load? we will give you demo and example for implement.In this post, we will learn about Get Query String Parameters from URL using JQuery with an example.

How to remove query string from URL using JQuery?

$(document).ready(function(){
	var url = window.location.toString();
	if (url.indexOf("?") > 0) {
	    var getPathFromUrl = url.substring(0, url.indexOf("?"));
	    window.history.replaceState({}, document.title, getPathFromUrl);
	}
});

Remove querystring from URL

Example 1:

function getPathFromUrl(url) {
  return url.split("?")[0];
}

Example 2:

var myWebsiteLiveURI = '/Members/Details?SortDirection=dsc&Sort=Age&Page=3&Page2=3';
var i;

// Testing the substring method
i = 0;
console.time('4cgnadhi substring');
while (i < 10000) {
    myWebsiteLiveURI.substring(0, myWebsiteLiveURI.indexOf('?'));
    i++;
}
console.timeEnd('4cgnadhi substring');

// Testing the split method
i = 0;
console.time('4cgnadhi split');
while (i < 10000) {
    myWebsiteLiveURI.split('?')[0]; 
    i++;
}
console.timeEnd('4cgnadhi split');

// Testing the RegEx method
i = 0;
var re = new RegExp("[^?]+");
console.time('4cgnadhi regex');
while (i < 10000) {
    myWebsiteLiveURI.match(re)[0]; 
    i++;
}
console.timeEnd('4cgnadhi regex');

I hope you get an idea about Remove Query String with JavaScript and HTML5.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Read Also:  PHP curl Http authentication header from Client

About Pakainfo

I am Jaydeep Gondaliya, a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Pakainfo →

Leave a Reply

Your email address will not be published. Required fields are marked *