$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>javascript - Form submit with target="_blank" opens a popup window after ajax request instead new tab - Stack |Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin12PV0评论

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);
Post a comment

comment list (0)

  1. No comments so far