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

admin2025-04-26  10

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);
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745664136a312928.html

最新回复(0)