Ajax request succeeded after new window window.open () blocked workaround

Source: Internet
Author: User

After the Ajax asynchronous request succeeds, it needs a new open window to open the URL, using the window.open () method, but the action is not triggered by the user, so it thinks it is unsafe to intercept (though if it is _self there is no limit), even if the Ajax The callback function simulates a user behavior such as click or submit (Trigger (' click ')), and the browser will not be considered to be actively triggered by the user and therefore cannot be safely executed, so it is intercepted.

Workaround:

1, asynchronous to synchronous, that is: Async:false

2. Point the new window to an object, and then modify the object's URL

Like what:

$ ('. Task '). bind (' click ',function() {    var w = window.open ();    $.ajax ({        ' POST ',        '/surveytask '        ,        ' json ',function  () {             w.close ();        },        function(res) {             = res.url;        }    } );});

Last note: The method of adding a new window on the web dynamically is not suitable for AJAX requests and is still blocked by the browser.

Ajax request succeeded after new window window.open () blocked workaround

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.