Javascript error replace on a string and url redirection

I wrote the following code, but there is a strange issue:
the algorithm is working but my localhost redirect to another port
for example :
http://localhost:8080 become http://localhost:8180 (or something like that)
When i put in comment the following line the port doesn’t change

url = url.replace(url[url.indexOf("&activeTabHomeAgregateSite=") + 27], toAppend);

so I’m sure the problem become from the line below but I don’t know why and I don’t know if there is another way to do this ?

 if (url.includes("&activeTabHomeAgregateSite=")) {
    url = url.replace(url[url.indexOf("&activeTabHomeAgregateSite=") + 27], toAppend);
    obj.href = url;
}


Source: javascript

Leave a Reply