Google analytics code

Saturday, December 1, 2012

Javascript : Updating the search parameters with window.location

I ran into an issue with Firefox not navigating to a new address I set via windows.location. Here's an example of a url I was trying to set.

window.location = "?page=account&this=that&foo=bar";

There's a property on the location object called search. When updating a partial url this should be used. = "?page=account&this=that&foo=bar";


  1. Does not seem to work on Firefox or Edge. I make the change, I see no difference in the URL. I press the refresh (F5) and all is same as before

    1. I opened the debug panel in FF and typed in ' = "?foo=bar'. It refreshed the page and added the search parameters to the URL.

  2. Try it this way.

    const params = new URLSearchParams(;
    params.set('x_variable', "value");
    window.history.replaceState({}, '', `${location.pathname}?${params}`);


If you found this page useful, or you have any feedback, please leave a comment.