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

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

Mar 20, 2019 am 10:15 AM
javascript

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article