简体   繁体   中英

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

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.

target="_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.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. In the end the browser will decide what is to happen, and most likely both methods will end up with the same result.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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