JavaScript opening new window instead of tab when command run too early
<p>I realize that you cannot control whether a browser opens a new <em>window</em> vs. a new <em>tab</em>, so this may have no solution.</p>

<p>The problem is basically that I run something like:</p>

<pre><code>function runCommand() {
   //...
   window.open(url);
}
</code></pre>

<p>This runs from time to time if the user presses a special key or clicks.  That all works fine, and it will open a new window or tab based on the user's browser settings.  Great.</p>

<p>The problem is, I also have some code:</p>

<pre><code>if (x.property) runCommand();
</code></pre>

<p>This will <em>always</em> open a the url in a new <em>window</em>, even though if you use <code>runCommand</code> at some other time on the same page, it will use a tab if that's the user's setting.</p>

<p>At first, I thought that it may have had to do with the page not being fully loaded, so I both tried wrapping it in <code>document.ready</code> and also using <code>setTimeout()</code> to some high number (like 5 seconds).  Even after doing that, <code>runCommand()</code> will <em>still</em> open a new window on the initial run even though it opens a new tab later on.  Has anyone experienced this behavior or know how to fix it?</p>

<p><strong>EDIT</strong>: I created a fiddle that showcases the problem.  Please excuse the popup: <a href="http://jsfiddle.net/csPGU/" rel="nofollow">http://jsfiddle.net/csPGU/</a></p>
