Home >Web Front-end >JS Tutorial >Solution to window.open() pop-up window being intercepted by browser
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 to JavaScript on the PHP Chinese website Tutorial video column!
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!