判断当前系统当前浏览器是否安装启用 Adobe Flash Player,检查在chrome中的状态

一、判断当前所在系统

let sUserAgent = navigator.userAgent;
let isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows");
let isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh") || (navigator.platform == "MacIntel");
if (isMac) return "Mac";
let isUnix = (navigator.platform == "X11") && !isWin && !isMac;
if (isUnix) return "Unix";
let isLinux = (String(navigator.platform).indexOf("Linux") > -1);
if (isLinux) return "Linux";
if (isWin) {
let isWin2K = sUserAgent.indexOf("Windows NT 5.0") > -1 || sUserAgent.indexOf("Windows 2000") > -1;
if (isWin2K) return "Windows2000";
let isWinXP = sUserAgent.indexOf("Windows NT 5.1") > -1 || sUserAgent.indexOf("Windows XP") > -1;
if (isWinXP) return "WindowsXP";
let isWin2003 = sUserAgent.indexOf("Windows NT 5.2") > -1 || sUserAgent.indexOf("Windows 2003") > -1;
if (isWin2003) return "Windows2003";
let isWinVista = sUserAgent.indexOf("Windows NT 6.0") > -1 || sUserAgent.indexOf("Windows Vista") > -1;
if (isWinVista) return "WindowsVista";
let isWin7 = sUserAgent.indexOf("Windows NT 6.1") > -1 || sUserAgent.indexOf("Windows 7") > -1;
if (isWin7) return "Windows7";
let isWin8 = sUserAgent.indexOf("Windows NT 6.2") > -1 || sUserAgent.indexOf("Windows 8") > -1;
if (isWin8) return "Windows8";
let isWin10 = sUserAgent.indexOf("Windows NT 10.0") > -1 || sUserAgent.indexOf("Windows 10") > -1;
if (isWin10) return "Windows10";
}
return "OtherOS";

二、判断当前浏览器内核

let Sys = {};
let ua = navigator.userAgent.toLowerCase();
let s;
(s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] :
(s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
(s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
(s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;

if (Sys.ie) {
console.log('ie core')
}
if (Sys.firefox) {
console.log('gecko core')
}
if (Sys.chrome || Sys.safari) {
console.log('webkit core')
}

三、判断浏览器是否安装 Adobe Flash Player

    let version = -1;
if (window.ActiveXObject) {
try {
let swf = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
version = parseInt(swf.Getletiable("$version").split(" ")[1].split(",")[0]);
}
catch (e) {
}
}
else {
if (navigator.plugins && navigator.plugins["Shockwave Flash"]) {
let arr = navigator.plugins['Shockwave Flash'].description.split(' ');
let i = 0;
let length = arr.length;
if (arr) {
for (; i < length; i++) {
if (!isNaN(Number(arr[i]))) {
version = Number(arr[i]);
break;
}
}
}
}
}
if (version == -1) {
//没有安装flash
} else {
//已安装flash
}
}

三、判断在Chrome中的状态
/* 检测flash在chrome中的状态
* 若flash已安装已启用已允许且是最新版
* 则 plugin.name 的值为 "pepflashplayer.dll"
* 否则 plugin.name 的值为 "internal-not-yet-present"
*/
for (var i = 0, len = navigator.plugins.length; i < len; i++) {
var plugin = navigator.plugins[i];
if (plugin.name == 'Shockwave Flash') {
if (plugin.filename == 'internal-not-yet-present') {

//plugin.name 的值为 "internal-not-yet-present"
        }
break;
}
}
posted @ 2017-03-17 16:01  SKILL·NULL  阅读(702)  评论(0编辑  收藏  举报