How to remove query string from URL using JQuery

Share Me
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Today now in this blog i will show you how to remove query string from url by using Jquery. Now here we will know how and why need to remove.

Why remove query strings?

Here is main two reasons for this.

  • Clear URL always look better than the long URL
  • When we are not remove our query string from URL. then all get variable show in our URL string. sometime it not good for a security

we can remove your query string using this simple Jquery code.

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

Read Also : How to store all record in laravel Cache

Thanks for read. I hope it help you. For more you can follow us onĀ facebook.

About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →