JS click element send ajax request open a new window often encounter such a requirement in the project, click an element, need to send ajax request, after the request is successful, the development needs to pass the link to the front-end (or open a new window after the request is successful), and the front-end needs to open the link through a new window. In fact, this principle may be very simple and easy to think, use window. open can open a new window, or click the div element. After an ajax request is sent successfully, the link is dynamically transmitted to the tag, and then the tag event is triggered, right? Once upon a time, I sent such a problem to the JS group. Many JS community friends said that long can't achieve this simple problem? How are you working on the front-end? Everyone thought it was very simple. After more than an hour of discussion, there was no result! Many people propose window. open. Someone else uses location. href = "" then set target = "_ blank" and so on. It is also suggested to use form to submit, but no matter how they use it, the results are the same, in the mainstream browsers firefox and chrome, the result is: it was intercepted by the browser! (Ie I Don't Care). Normally, it's okay to click an element and open a new webpage with window. open, and it won't be intercepted by the browser! Everyone knows this, but why do I need to send ajax requests one more step and the requests are intercepted by the browser? To solve this problem, you must make a demo. I did this: <div class = "testA" style = "cursor: pointer; "> click I to bring up a new window </div>. JS: copy the code $ ('. testA '). unbind ('click '). bind ('click', function () {$. ajax ({url: 'http: // localhost/demo/windowopen/test. php ', 'type': 'post', ype: 'json', success: function (data) {if (data & data. success) {window. open ('HTTP: // www.baidu.com ') ;}}) ;}); copy the code URL. I can either make a request or use the same domain, this is an asynchronous ajax request. To solve this problem, we can And firefox and chrome won't be blocked! The JS Code is as follows: copy the code $ ('. testA '). unbind ('click '). bind ('click', function () {$. ajax ({url: 'http: // localhost/demo/windowopen/test. php ', 'type': 'post', async: false, dataType: 'json', success: function (data) {if (data & data. success) {window. open ('HTTP: // www.baidu.com ') ;}}) ;}); copy the code to set the synchronous request. (async: false ). Everyone can test it!