function updateUrl(urlParametersId) { if (history.replaceState) { var newParameters = document.getElementById(urlParametersId).value; var oldParameters = ""; var lastIndex = location.href.lastIndexOf("?"); if (lastIndex != -1) { oldParameters = location.href.substring(lastIndex + 1); if (oldParameters != newHref) { var newHref = location.href.substring(0, lastIndex + 1) + newParameters; history.replaceState({}, document.title, newHref); } } else { history.replaceState({}, document.title, location.href + "?" + newParameters); } } }