Fichtelgard

URL-Parameter updaten

export function updateURLParameter(
url: string,
param: string,
paramVal: string
) {
let TheAnchor = null;
let newAdditionalURL = "";
let tempArray = url.split("?");
let baseURL = tempArray[0];
let additionalURL = tempArray[1];
let temp = "";

if (additionalURL) {
let tmpAnchor = additionalURL.split("#");
let TheParams = tmpAnchor[0];
TheAnchor = tmpAnchor[1];
if (TheAnchor) additionalURL = TheParams;

tempArray = additionalURL.split("&");

for (let i = 0; i < tempArray.length; i++) {
if (tempArray[i].split("=")[0] !== param) {
newAdditionalURL += temp + tempArray[i];
temp = "&";
}
}
} else {
let tmpAnchor = baseURL.split("#");
let TheParams = tmpAnchor[0];
TheAnchor = tmpAnchor[1];

if (TheParams) baseURL = TheParams;
}

if (TheAnchor) paramVal += "#" + TheAnchor;

let rows_txt = temp + "" + param + "=" + paramVal;
return baseURL + "?" + newAdditionalURL + rows_txt;
}