Set lub zaktualizować URL/QueryString Parameter i aktualizuj URL przy użyciu historii HTML.replaceState()
Można spróbować czegoś takiego:
var updateQueryStringParam = function (key, value) {
var baseUrl = [location.protocol, '//', location.host, location.pathname].join(''),
urlQueryString = document.location.search,
newParam = key + '=' + value,
params = '?' + newParam;
// If the "search" string exists, then build params from it
if (urlQueryString) {
keyRegex = new RegExp('([\?&])' + key + '[^&]*');
// If param exists already, update it
if (urlQueryString.match(keyRegex) !== null) {
params = urlQueryString.replace(keyRegex, "$1" + newParam);
} else { // Otherwise, add it to end of query string
params = urlQueryString + '&' + newParam;
}
}
window.history.replaceState({}, "", baseUrl + params);
};
'/ ([? &] z) = ([^ # &]*)/g; 'musi być użyty zamiast'/([? &] Z) = ([^ &]*)/g; ', ponieważ może on zastąpić ten fragment – Zulakis
@Zulakis Dobrze, po aktualizacji. :) – BuddhiP
Krótkie i dobre rozwiązanie. :) –