title: Opening new window/tab without using `window.open` or `window.location.href`
body: <p>I want to generate a link that is clicked right after creating, but nothing happens</p>
  <p>Code:</p>
  <pre><code>var link = $(&quot;&lt;a&gt;&lt;/a&gt;&quot;);
  link.attr(&quot;href&quot;, &quot;/dostuff.php&quot;);
  link.attr(&quot;target&quot;, &quot;_blank&quot;);
  link.click();
  </code></pre>
  <p>The attributes are set correctly:</p>
  <pre><code>var link = $(&quot;&lt;a&gt;&lt;/a&gt;&quot;);
  link.attr(&quot;href&quot;, &quot;/dostuff.php&quot;);
  link.attr(&quot;target&quot;, &quot;_blank&quot;);
  var linkcheck = link.wrap('&lt;p&gt;').parent().html();
  console.log(linkcheck);
  </code></pre>
  <p>This returns:</p>
  <pre><code>&lt;a href=&quot;/dostuff.php&quot; target=&quot;_blank&quot;&gt;&lt;/a&gt; 
  </code></pre>
  <p>No errors</p>
  <hr />
  <h2>UPDATE</h2>
  <p>I tried to append it, bind click to it, click it and remove it</p>
  <pre><code>var link = $(&quot;&lt;a&gt;&lt;/a&gt;&quot;);
  link.attr(
  {
      id    : &quot;linky&quot;,
      href  : &quot;/dostuff.php&quot;,
      target: &quot;_blank&quot;
  });
  $(&quot;body&quot;).append(link);
  $(&quot;#linky&quot;).on(&quot;click&quot;, function() { console.log(&quot;Link clicked&quot;); });
  $(&quot;#linky&quot;).click();
  $(&quot;#linky&quot;).remove();
  </code></pre>
  <p>The click action is being executed, but the default action (open the link) isn't..</p>
  <hr />
  <h2>UPDATE2</h2>
  <p>I have found the solution: creating and submitting a <code>&lt;form&gt;</code>! <a href="https://stackoverflow.com/a/11736910/1062281">See my answer.</a></p>