skip to Main Content

I have the following url modification script

var path = window.location.href
path=path.replace(/&/g, "&");
window.location.href=path;

The page keeps reloading…
What should I do to make the page reload only once?

2

Answers


  1. where did you add window.location.href = path ? directly in the script element of the page ? if so, of course it should reload, as the navigator executes the script code each time it loads.
    Anyways, you need to upload the whole code, so we can help you.

    Login or Signup to reply.
  2. You should modify your script so window.location.href=path; is only called if & is detected

    something like:

    const path = window.location.href
    if (path.includes("&")) {
      window.location.href=path.replace(/&/g, "&");
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search