I want to update the url query string by clicking on checkbox. Here's the code, it doesn't work correctly
param1=param1=true
param1=param1=param1=false
param1=param1=param1=param1=true
instead of:
param1=false
param1=true
Here's an unrefactored code:
if (this.checked) {
if (window.location.href.search('[?&]') === -1) {
window.history.pushState('object or string', 'Title', window.location.href + '?param1=true');
} else {
window.history.pushState('object or string', 'Title', window.location.href.replace(/param1=false|true/i, 'param1=true'));
}
} else {
if (window.location.href.search('[?&]') === -1) {
window.history.pushState('object or string', 'Title', window.location.href + '?param1=false');
} else {
window.history.pushState('object or string', 'Title', window.location.href.replace(/param1=false|true/i, 'param1=false'));
}
}