修改URL参数

function replaceParamVal(paramName, replaceWith, isRefresh) {
var oUrl = window.location.href.toString();
if (paramName && replaceWith) {
if (oUrl.indexOf(paramName + “=” + replaceWith) > 1) {
return;
}
}
if (oUrl.indexOf(‘&’+paramName+‘=’) > 0) {
var re = eval(‘/(&’ + paramName + ‘=)([^&]*)/gi’);
var nUrl = oUrl.replace(re, ‘&’+paramName + ‘=’ + replaceWith);
} else {
if (oUrl.indexOf(“?”) > 0) {
var nUrl = oUrl + “&” + paramName + “=” + replaceWith;
} else {
var nUrl = oUrl + “?” + paramName + “=” + replaceWith;
}
}
if (isRefresh) {
// window.location.href = nUrl
window.location.reload()
}
var stateObject = { id: “” };
var title = “”;
history.replaceState(stateObject, title, nUrl);
}

你可能感兴趣的:(实际开发总结-前端,javascript,前端,html)