3

I'm using this bit of javascript in a .NET 4.0 web application for IE8:

ClientScript.RegisterStartupScript(this.Page.GetType(), "popupOpener", "var popup=window.open('Report.aspx');popup.focus();", true);

This opens an .aspx page in a new browser tab.

However, it does not give the tab focus, which I would very much like to do. Does anyone know how to achieve this?

Josh Darnell
  • 11,304
  • 9
  • 38
  • 66
tmaurst
  • 552
  • 3
  • 14
  • 34
  • Have you seen this: http://stackoverflow.com/questions/726761/javascript-open-in-a-new-window-not-tab ? – xtrem Jan 18 '12 at 23:06
  • @Moussa: That question appears to deal with whether the new document is opened in a new tab or as a new window. That aside, so long as the JS has a window handler, it should still be able to control focus (among other things). – buley Jan 18 '12 at 23:09
  • A button creates/formats a report document, where it is then stored in a session variable. Then this javascript opens the new aspx window where the report document is loaded into a viewer. – tmaurst Jan 18 '12 at 23:24
  • opening and focusing a new window in a tab will depend on the browser setting and cannot be overridden by javascript. as for firefox, you can set that in its setting. – Alvin Jan 19 '12 at 01:10

1 Answers1

0

Not all browsers support focus, and I believe there are some bugs even among those that do.

Try to blur the window before giving it focus. It's bizarre but has worked for folks in the past.

In general:

popup_handle.blur();
popup_handle.focus();

As applies to your code:

ClientScript.RegisterStartupScript(this.Page.GetType(), "popupOpener", "var popup=window.open('Report.aspx');popup.blur();popup.focus();", true);
buley
  • 28,032
  • 17
  • 85
  • 106