title: Javascript changing url param doesn't take effect
body: <p>I'm trying to refresh the page with some custom param (lang) using javascript in order to change the langage used.</p>
  
  <p>My Back-end knowns about the choosen language using the query param lang which may be "en" for english or "fr" for french.</p>
  
  <p>When i add manually the param in the browser it works just fine, but when using javascript, i get the right url (displayable using alert) but the url in the browser textbox stays same.</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html xmlns:th="http://www.thymeleaf.org"&gt;
  &lt;body&gt;
  &lt;ul th:fragment="languages-chooser" class="navbar-nav ml-auto"&gt;
      &lt;style&gt;
          .flag-icon {
              font-size: 20px !important;
          }
      &lt;/style&gt;
  
      &lt;li class="badge badge-light nav-item mr-3"&gt;
          &lt;a href="" onclick="change_language('en')"&gt;
              &lt;span class="flag-icon flag-icon-us"&gt;&lt;/span&gt;
          &lt;/a&gt;
      &lt;/li&gt;
  
      &lt;li class="badge badge-light nav-item mr-3"&gt;
          &lt;a href="" onclick="change_language('fr')"&gt;
              &lt;span class="flag-icon flag-icon-fr"&gt;&lt;/span&gt;
          &lt;/a&gt;
      &lt;/li&gt;
  
      &lt;script&gt;
          function change_language(lang) {
              localStorage.lang = lang;
  
              alert("new url: " + updateUrlParam("lang", lang));
  
              window.location.href = updateUrlParam("lang", lang);
          }
  
          function updateUrlParam(key, value, url) {
              if (!url)
                  url = window.location.href;
  
              var re = new RegExp("([?&amp;])" + key + "=.*?(&amp;|#|$)(.*)", "gi"),
                  hash;
  
              if (re.test(url)) {
                  if (typeof value !== 'undefined' &amp;&amp; value !== null) {
                      return url.replace(re, '$1' + key + "=" + value + '$2$3');
                  }
                  else {
                      hash = url.split('#');
                      url = hash[0].replace(re, '$1$3').replace(/(&amp;|\?)$/, '');
                      if (typeof hash[1] !== 'undefined' &amp;&amp; hash[1] !== null) {
                          url += '#' + hash[1];
                      }
                      return url;
                  }
              }
              else {
                  if (typeof value !== 'undefined' &amp;&amp; value !== null) {
                      var separator = url.indexOf('?') !== -1 ? '&amp;' : '?';
                      hash = url.split('#');
                      url = hash[0] + separator + key + '=' + value;
                      if (typeof hash[1] !== 'undefined' &amp;&amp; hash[1] !== null) {
                          url += '#' + hash[1];
                      }
                      return url;
                  }
                  else {
                      return url;
                  }
              }
          }
      &lt;/script&gt;
  &lt;/ul&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>