New Windows window.open () blocked solution _ajax related after successful Ajax request

Source: Internet
Author: User

Problem:

Before the development of the project encountered a problem, Ajax asynchronous request after the success of the new open window to open the URL, using the window.open () method, but unfortunately by the browser to intercept, how to solve this problem?
Analysis:

The browser intercepts a new open window because it is not the user's active trigger, so it thinks it is unsafe to intercept (but if it is _self, there is no limit), even if the Ajax callback function simulates performing user actions such as click or submit (trigger) (' Click '), the browser will also think that the user is not actively triggered, so can not be safely executed, so be intercepted.
Workaround:

1, asynchronously changed to synchronous, namely: Async:false

2. Point the new open window to an object, and then modify the URL of the object, such as:

$ ('. Task '). bind (' click ', Function () {
var w = window.open ();
$.ajax ({
type: ' POST ',
URL: '/surveytask ',
dataType: ' json ',
error:function () {
w.close ();
} ,
success:function (res) {
w.location = Res.url;
}
});

Finally, the need to explain: the dynamic addition of the Web Form new window method, is not suitable for AJAX requests, at least the Bo Master test is still blocked by the browser.

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.