Javascript 在 Chrome 中以“_blank”为目标的 window.open
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11035937/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
window.open with target "_blank" in Chrome
提问by Jan-Patrick Ahnen
I have a small javascript function which opens an url in a new tab:
我有一个小的 javascript 函数,它在新选项卡中打开一个 url:
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
这在通过单击按钮调用客户端时始终有效,即使在 chrome 中也是如此。但是在 Chrome 中,当它通过使用从服务器端(!)调用时它将不起作用
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?
在 Firefox 和 IE 中,它会在新选项卡中打开 url,但 chrome 在新窗口中打开 url。强制 Chrome 在新标签页中打开它的解决方法是什么?
采纳答案by Dennis Traub
It's a setting in chrome. You can't control how the browser interprets the target _blank
.
这是 chrome 中的设置。您无法控制浏览器如何解释 target _blank
。
回答by Jordan
"_blank" is not guaranteed to be a new tab or window. It's implemented differently per-browser.
“_blank”不保证是新标签或窗口。每个浏览器的实现方式不同。
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.
但是,您可以将任何内容放入目标中。我通常只说“_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.
请注意,这意味着它是一个命名目标,因此如果您尝试打开 2 个 URL,它们将使用相同的选项卡。
回答by Evan Harper
As Dennis says, you can't control how the browser chooses to handle target=_blank.
正如丹尼斯所说,您无法控制浏览器如何选择处理 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.
如果您想知道不一致的行为,可能是弹出窗口阻止。许多浏览器将禁止打开新窗口,但允许作为鼠标单击事件的最终结果生成新窗口。
回答by Guillermo
window.open(skey, "_blank", "toolbar=1, scrollbars=1, resizable=1, width=" + 1015 + ", height=" + 800);
回答by Aelios
You can't do it because you can't have control on the manner Chrome opens its windows
您不能这样做,因为您无法控制 Chrome 打开其窗口的方式