9

I need some help here...

Anyone knows how to solve this?: http://jsfiddle.net/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.com');
        });

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

    });
})(jQuery);

Thanks!

2
  • What are you trying to achieve with this, it looks like a horrible hack.
    – Ja͢ck
    Jan 22, 2013 at 12:48
  • Any update on this? We are experiencing the same problem. Mar 6, 2013 at 18:40

1 Answer 1

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.com')}, 10);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.