views:

300

answers:

2

I have some JavaScript that makes an AJAX call and, if the call fails, opens a new windows (tab in Firefox) and displays the response from the server in that window. This is very convenient for debugging, because the error is typically from Pylons, so it's a full HTML page.

The only problem is that the new tab becomes the active tab, which would totally confuse a regular user. Is there any way to open the tab/window, but not make it active, ie. keep the current active window?

My code currently looks like this:

 errorWindow = window.open("", "TCerrorWindow")
 if (errorWindow)
  errorWindow.document.write(xhr.responseText);
+3  A: 

AFAIK this is not possible, as a security measure against pop-under windows. For debugging purposes you could

  • use Firebug (with a handy console, where you can output your own log messages from the code)
  • create a debug layer (div) on your page, where you output error messages in case an error happens
simon
+5  A: 

You can call errorWindow.blur(); window.focus(); after, forcing the browser to return focus to the previous window.

The effect you're trying to achieve is commonly called a pop-under window.

Duroth
This works in IE8 and works in Firefox if a new WINDOW is opened (by specifying a window size in window.open). It doesn't work with tabs, but I suppose there's no way to do that, so I'm accepting your answer. Thanks!
Evgeny