简体   繁体   English

target =“ _ blank”弹出一个窗口,而不是打开一个新选项卡

[英]target=“_blank” pop-ups a window instead of open a new tab

I have a weird issue with a "form" generated from js. 我有一个从js生成的“表单”的怪异问题。 The code is something like this: 代码是这样的:

var form_ = 
    '<form method="get" action="/foo/bar/" target="_blank">' +
        '<input type="hidden" name="a" value="' + a + '"/>' +
        '<input type="hidden" name="b" value="' + b +'"/>' +
        '<input type="hidden" name="c" value="' + c + '"/>' +
    '</form>';

$(form_).appendTo('body').submit().remove();

a is string variable that contains a date ( dd/mm/yyyy ) and b,c are numbers. a是包含日期( dd/mm/yyyy )的字符串变量,而b,c是数字。

I use this snippet of code in a lot of places around the app, in fact there is a very similar code in the same HTML that opens a new tab as I expect, but this particular one tries to pop-up a window instead. 我在应用程序的许多地方都使用了此代码段,实际上,在同一HTML中有一个非常相似的代码,可以按我的期望打开一个新选项卡,但是这个特定代码试图弹出一个窗口。

I've tried with Firefox, Chrome and IE. 我已经尝试使用Firefox,Chrome和IE。

target="_blank" is used to open targets in new windows. target="_blank"用于在新窗口中打开目标。 The fact that most modern browsers open new tabs instead is not defined by any standard and is usually controlled by user via settings. 相反,大多数现代浏览器都打开新选项卡的事实并没有任何标准定义,通常由用户通过设置来控制。

If you have your browser set to open new links in a tab rather than in a window, and that doesn't work in this case you have probably found a bug. 如果您将浏览器设置为在选项卡而非窗口中打开新链接,并且在这种情况下不起作用,则可能是您发现了一个错误。

Do the other places around your app post form or are they simply links? 应用程序周围的其他地方是表单还是仅仅是链接?

The behaviour for opening new tabs or new instances of the browser are configurable for Internet Explorer 9 (Tools|InternetSettings|Tabs|Settings) 可以为Internet Explorer 9配置打开新选项卡或浏览器新实例的行为(工具| InternetSettings | Tabs | Settings)

In Firefox, these options are in Tools|Options|tabs 在Firefox中,这些选项位于“工具” |“选项” |“选项卡”中

Chrome doesn't seem to have a setting for this, but you can choose between new window or new tab, by right-clicking on a link. Chrome似乎没有为此设置,但是您可以通过右键单击链接在新窗口或新标签之间进行选择。

From the answer given here: http://www.plus2net.com/html_tutorial/submit-new.php 从此处给出的答案中: http : //www.plus2net.com/html_tutorial/submit-new.php

<form name="f1" type="post" action="test5.html">
<input type="submit" value="Open default action file test5.html" onclick="this.form.target='_blank';return true;" />
</form>

EDIT: this works for me in Chrome, but I see no reason why this should generate any different behaviour going through JS or not. 编辑:这在Chrome中对我有效,但是我看不出为什么它会通过JS产生任何不同的行为。 In the end the browser will decide what is to happen, and most likely both methods will end up with the same result. 最后,浏览器将决定将要发生的情况,并且很可能两种方法最终都会得到相同的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM