Removing Query String from URL by using jquery (working with issue)
keep on refreshing the page upto nth time.
This is because you are not checking whether the URL has a query string or not. So it is an infinite refresh.
You can try this:
$(document).ready(function(){
if (window.location.href.indexOf('?') > -1) {
window.location.href = window.location.pathname;
}
});
Edit 1: Is it possible to remove query string without page refresh?
You can try this:
$(document).ready(function(){
if (window.location.href.indexOf('?') > -1) {
history.pushState('', document.title, window.location.pathname);
}
});
var uri = window.location.href.toString();
if (uri.indexOf("?") > 0) {
var clean_uri = uri.substring(0, uri.indexOf("?"));
window.history.replaceState({}, document.title, clean_uri);
}
setting a value to window.location.href will reload the page. Try this:
var url = window.location.href;
var a = url.indexOf("?");
var b = url.substring(a);
var c = url.replace(b,"");
url = c;