23

I have a small javascript function which opens an url in a new tab:

function RedirectToPage(status) {
   var url = 'ObjectEditor.aspx?Status=' + status;
   window.open(url , '_blank');
}

This always works when called client-side by clicking a button, even in chrome. But in Chrome it won't work when it's called from server-side(!) by using

ScriptManager.RegisterClientScriptBlock()

In Firefox and IE it opens the url in a new tab, but chrome opens the url in a new window. What could be a workaround to force Chrome to open it in a new tab?

Jan-Patrick Ahnen
  • 1,380
  • 6
  • 17
  • 31

5 Answers5

20

It's a setting in chrome. You can't control how the browser interprets the target _blank.

Dennis Traub
  • 50,557
  • 7
  • 93
  • 108
  • 2
    But why does Chrome open the url in a new tab if the function is called from client-side when a button is clicked? It just doesn't work when it's called by using the server-side approach. – Jan-Patrick Ahnen Jun 14 '12 at 15:13
  • 1
    Probably it's pop-up blocking. Many browsers will forbid new windows from being opened apropos of nothing, but will allow new windows to be spawned as the eventual result of a mouse-click event. – Evan Harper Oct 18 '12 at 12:42
  • Browsers have internal variables that indicate information about how and where the call originated (top of call stack) e.g. the browser will decide to handle the opening (or blocking) of popups in a separate window or new tab based on whether the call originated from a particular event (load event vs click event vs async callback). – Chris Walsh Dec 05 '16 at 16:16
19

"_blank" is not guaranteed to be a new tab or window. It's implemented differently per-browser.

You can, however, put anything into target. I usually just say "_tab", and every browser I know of just opens it in a new tab.

Be aware that it means it's a named target, so if you try to open 2 URLs, they will use the same tab.

Jordan
  • 31,971
  • 6
  • 56
  • 67
2
window.open(skey, "_blank", "toolbar=1, scrollbars=1, resizable=1, width=" + 1015 + ", height=" + 800);
zero323
  • 322,348
  • 103
  • 959
  • 935
Guillermo
  • 39
  • 1
0

You can't do it because you can't have control on the manner Chrome opens its windows

Aelios
  • 11,849
  • 2
  • 36
  • 54
0

As Dennis says, you can't control how the browser chooses to handle target=_blank.

If you're wondering about the inconsistent behavior, probably it's pop-up blocking. Many browsers will forbid new windows from being opened apropos of nothing, but will allow new windows to be spawned as the eventual result of a mouse-click event.

Evan Harper
  • 430
  • 3
  • 15