How to remove query string from URL using JQuery

By Hardik Savani | February 17, 2016 | | 66854 Viewer | Category : jQuery


Why remove query strings?

Main two reasons for this.

1. Clear URL alwaya look better than the long URL

2. When you are not remove your query string from URL. then all get variable show in you URL string. sometime it not good for a security

You 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);

}

});



Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.