After the ajax asynchronous request is successful, you need to open a new window to open the url. The window. open () method is used, but unfortunately it is intercepted by the browser. How can this problem be solved:
A problem occurred during the previous development project. After the ajax asynchronous request is successful, you need to open a new window to open the url, using window. open () method, but unfortunately it was intercepted by the browser. How can this problem be solved?
Analysis:
The browser intercepts new windows because this operation is not manually triggered by the user. Therefore, the browser considers this operation unsafe and intercepts it (but if it is _ self, there will be no such restriction ), even if the ajax callback function simulates the execution of user behaviors such as click or submit (trigger ('click'), the browser will think that it is not triggered by the user, so it cannot be safely executed, so it is intercepted.
Solution:
1. Change asynchronous mode to synchronous mode, that is, async: false
2. Point the new window to an object and modify the object url, for example:
$ ('. 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, it should be noted that the method of dynamically adding a new form window on the Internet is not suitable for ajax requests. At least the blogger tested it and was still intercepted by the browser.
After successful ajax requests, open window. open () is blocked. For more information, see PHP!