A query string is the part of a URL that includes field-value pairs.
Here we are going to remove query string from URL using JavaScript.
There are number of benefits of clean URL.
Clean URL always looks better and prevent user to see if you are tracking where they came from.
It is helpful for security reasons.
Example 1 :
- $(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);
- }
- });
- var clean_uri = location.protocol + "//" + location.host + location.pathname;
- window.history.replaceState({}, document.title, clean_uri);