window.open 防止浏览器拦截

https://blog.csdn.net/sinat_37255207/article/details/89374416

 

网上试了很多方法 最终只有一种可以 

 

var newWin = window.open('https://www.baidu.com/');
 
wxPublic().then(res=>{
 
// 重定向到目标页面
 
if(res.data.statusCode!='200'){
 
newWin.location.href ='404页面';
 
return;
 
}
 
newWin.location.href = res.data.responseContent.url;
 
}).catch(()=>{
 
newWin.location.href ='404页面';
 
//失败重定向到404html
 
})

如果 网速慢的话 接口反馈慢  会出现重定向太慢 很长时间停留在 百度页面  所以 最好 先window.open 一个固定好的 loading HTML  失败的话 可以跳转404HTML 也可以 newWin.close 关闭对应的新弹框 

posted @ 2019-04-18 11:13  天渺工作室  阅读(817)  评论(0编辑  收藏  举报