Home > Web Front-end > JS Tutorial > body text

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

不言
Release: 2019-03-20 10:15:41
forward
5929 people have browsed it

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);  //会被拦截
             }
        })
    }
});  
Copy after login

Solution

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

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!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template