How to remove query string from URL using JQuery

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


Share this post:

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

}

});