window.open被拦截解决

3,957 阅读1分钟

项目开发中遇到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);
    })