admin管理员组文章数量:1287621
I have a weird issue with a "form" generated from 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.
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.
I've tried with Firefox, Chrome and IE.
I have a weird issue with a "form" generated from 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.
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.
I've tried with Firefox, Chrome and IE.
Share Improve this question edited Feb 21, 2012 at 9:25 user647772 asked Feb 20, 2012 at 11:05 codevinceDevcodevinceDev 411 silver badge4 bronze badges 1- Is there any reason you want it to submit and open the form in a new tab? – Aram Kocharyan Commented Feb 20, 2012 at 11:09
3 Answers
Reset to default 8target="_blank"
is used to open targets in new windows. 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)
In Firefox, these options are in Tools|Options|tabs
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.
From the answer given here: http://www.plus2net./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. In the end the browser will decide what is to happen, and most likely both methods will end up with the same result.
本文标签: javascripttargetquotblankquot popups a window instead of open a new tabStack Overflow
版权声明:本文标题:javascript - target="_blank" pop-ups a window instead of open a new tab - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741270405a2369177.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论