Pass a url from the backend, and after receiving it, the frontend will open a new window and jump to this link.
Use window.open(url, '_blank');
to be intercepted by the browser.< /p>
Is there any way to achieve this? I tried simulating the click of the a tag and it still intercepted it. The pop-up p failed to load the iframe, and the window must be opened.
The problem has been solved, see the accepted answer.
For this question, we must first understand why it is intercepted. The browser will make "non-artificial" calls
window.open
的弹窗进行拦截,什么叫做"非人为"的,就是浏览器判断在用户操作和window.open
之间不是连续的,浏览器会认为可能是流氓程序弹出的广告窗口从而进行拦截从楼主的描述可以看出,楼主应该是进行某个操作之后,通过ajax去获取一个url,然后通过
window.open
打开页面,我们都知道ajax是异步的,浏览器就认为不是连续的,所以就拦截了解决方法可以先在操作(比如点击)的时候,直接
window.open
, and then go to ajax to obtain the data, and then assign a URL to the opened window. The approximate pseudo code is as follows:There’s nothing wrong with it.
Why add _blank?
If the url has an http or https header
Write the event that triggers the method as an a tag, write the logic of obtaining the URL in the Controller pointed to by the a tag, and then return to a new page, bypassing the window.open method in short
For security reasons, the browser will automatically block pop-ups
Only a command that opens a new window within a short period of time after the user clicks it, such as
window.open
, will not be intercepted. This is a security restriction of the browser.Try adding one more parameter to the ajax request:
async: false