title: JavaScript - redirect to URL in new browser tab with params
body: <p>Below there is a function which allows to perform redirection method with some headers params. Everything works good but I want to open such redirection in a new browser tab (aka window open or target="_blank").</p>
  
  <p>What should I change within below code ?
  Thanks!</p>
  
  <pre><code>function gotoUrl(path, params, method) {
      method = method || "post"; 
  
      var form = document.createElement("form");
      form.setAttribute("method", method);
      form.setAttribute("action", path);
  
      //Fill the hidden form
      if (typeof params === 'string') {
          var hiddenField = document.createElement("input");
          hiddenField.setAttribute("type", "hidden");
          hiddenField.setAttribute("name", 'data');
          hiddenField.setAttribute("value", params);
          form.appendChild(hiddenField);
      }
      else {
          for (var key in params) {
              if (params.hasOwnProperty(key)) {
                  var hiddenField = document.createElement("input");
                  hiddenField.setAttribute("type", "hidden");
                  hiddenField.setAttribute("name", key);
                  if(typeof params[key] === 'object'){
                      hiddenField.setAttribute("value", JSON.stringify(params[key]));
                  }
                  else{
                      hiddenField.setAttribute("value", params[key]);
                  }
                  form.appendChild(hiddenField);
              }
          }
      }
  
      document.body.appendChild(form);
      form.submit();
  }
  </code></pre>