javascript - Form submit with target="_blank" opens a popup window after ajax request instead new tab - Stack

I need some help here...Anyone knows how to solve this?: When I submit a form with target="_blank

I need some help here...

Anyone knows how to solve this?: /

When I submit a form with target="_blank" by defaults opens a new tab. But if try to do it after an ajax request, the forms opens a popup window.

(function($) {
    jQuery(document).ready(function() {

        var launch = function(p_url) {
            var form = $('<form />').hide();
            form.attr({'action': p_url, 'target': '_blank'});
            form.appendTo(document.body);
            form.submit();
            form.remove();
            delete form;
        };

        $('#normal').on('click', function() {
            launch('');
        });

        $('#ajax').on('click', function() {
            $.ajax({
                type: 'POST',
                url: '#',
                traditional: true,
                success: function() {
                    launch('');
                }
            });
        });

    });
})(jQuery);

Thanks!

I need some help here...

Anyone knows how to solve this?: http://jsfiddle/Q3BfC/5/

When I submit a form with target="_blank" by defaults opens a new tab. But if try to do it after an ajax request, the forms opens a popup window.

(function($) {
    jQuery(document).ready(function() {

        var launch = function(p_url) {
            var form = $('<form />').hide();
            form.attr({'action': p_url, 'target': '_blank'});
            form.appendTo(document.body);
            form.submit();
            form.remove();
            delete form;
        };

        $('#normal').on('click', function() {
            launch('http://www.google.');
        });

        $('#ajax').on('click', function() {
            $.ajax({
                type: 'POST',
                url: '#',
                traditional: true,
                success: function() {
                    launch('http://www.google.');
                }
            });
        });

    });
})(jQuery);

Thanks!

Share Improve this question edited Jan 22, 2013 at 12:03 Prisoner 27.7k11 gold badges76 silver badges103 bronze badges asked Jan 22, 2013 at 12:03 Marcos EsperónMarcos Esperón 911 silver badge2 bronze badges 2
  • What are you trying to achieve with this, it looks like a horrible hack. – Ja͢ck Commented Jan 22, 2013 at 12:48
  • Any update on this? We are experiencing the same problem. – Hudson Atwell Commented Mar 6, 2013 at 18:40
Add a ment  | 

1 Answer 1

Reset to default 4

Its not trying to open it as a popup but its blocked by the popup blocker cause open something with target:_blank in a new tab is only allowed when it is the direct result of an user input, like click or keydown.

You will get the same result when you try to open it in a setTimeout:

setTimeout(function() {launch('http://www.google.')}, 10);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745664135a4639021.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信