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.