I realize that you cannot control whether a browser opens a new window vs. a new tab, so this may have no solution.
The problem is basically that I run something like:
function runCommand() {
//...
window.open(url);
}
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.
The problem is, I also have some code:
if (x.property) runCommand();
This will always open a the url in a new window, even though if you use runCommand at some other time on the same page, it will use a tab if that’s the user’s setting.
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 document.ready and also using setTimeout() to some high number (like 5 seconds). Even after doing that, runCommand() will still 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?
EDIT: I created a fiddle that showcases the problem. Please excuse the popup: http://jsfiddle.net/csPGU/
I’m guessing it’s something to do with the browser itself and the way that the browsers try to deal with windows that are opened programatically.
I assume that when you
runCommandlater on it’s based on an event that has occurred (clicking on something for instance). Browsers generally allow new windows that are triggered by events, but block those that had no interaction (typically popups).