Skip to content

Instantly share code, notes, and snippets.

@liuwenzhuang
Created March 30, 2018 02:24
Show Gist options
  • Save liuwenzhuang/d1000648b2d5c72819ea0a5ec9424118 to your computer and use it in GitHub Desktop.
Save liuwenzhuang/d1000648b2d5c72819ea0a5ec9424118 to your computer and use it in GitHub Desktop.
判断window.open打开的页面是否成功;judge whether window.open is blocked or not.
/**
* 判断window.open打开页面是否被拦截
* @return {boolean} true表示被拦截,false表示未被拦截
*/
function isWindowOpenBlocked() {
var isBlocked = false;
try {
var winRef = window.open(URL, WINDOWNAME[, WINDOWFEATURES]);
if(winRef == null) { // 浏览器拦截
isBlocked = true;
}
} catch (e) {
isBlocked = true; // 插件、应用拦截
}
return isBlocked;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment