window.open被拦截解决


title: window.open被拦截解决
cover: /img/4.jpg

项目开发中遇到window.open写在回调里被浏览器拦截.
解决办法是在请求时新开一个tab页,然后再请求的回调里修改这个tab页的地址.

let newWindow = window.open('about:blank'); //  新开一个tab页返回一个window对象
axios.post(url})
    .then(response=>{
        if(response.data.status.code === 1){
            newWindow.location.href = '' //  修改新开页面的地址
        }
    })
    .catch(error=>{
        console.log(error);
    })

猜你喜欢

转载自blog.csdn.net/qq_38606793/article/details/88049880