Home>Article>Web Front-end> Solution to window.open() pop-up window being intercepted by browser

Solution to window.open() pop-up window being intercepted by browser

不言
不言 forward
2019-03-20 10:15:41 5828browse

The content of this article is about the solution to the window.open() pop-up window being intercepted by the browser. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Under what circumstances will the pop-up window be intercepted?

When window.open triggers an event for the user internally or when loading, it will not be intercepted. Once the pop-up code is moved to Within ajax or a piece of asynchronous code, it will be intercepted immediately.

obj.onclick = function(){ window.open(url) // 会被拦截 } obj.onclick = function () { ajax({ url: '/xxxxxx/', success: function (url) { window.open(url); //会被拦截 } }) } });  

Solution

obj.onclick = function () { var newWindow = window.open(); //先在回调函数之前打开新窗口,后再加载url ajax({ url: '/xxxxxx/', success: function (url) { newWindow.location.href = url; } }) }

This article has ended here. For more other exciting content, you can pay attention toJavaScript on the PHP Chinese website Tutorial videocolumn!

The above is the detailed content of Solution to window.open() pop-up window being intercepted by browser. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete