Javascript检测系统信息各个浏览器信息

来源:http://www.sh-fengwen.com 作者: 营养排行 人气:108 发布时间:2019-09-04
摘要:var sUserAgent = navigator.userAgent; var fAppVersion = parseFloat(navigator.appVersion); //比较浏览器版本大小 function compareVersions(sVersion1,sVersion2){     var aVersion1 = sVersion1.split(".");     var aVersion2 = sVers

var sUserAgent = navigator.userAgent;
var fAppVersion = parseFloat(navigator.appVersion);
//比较浏览器版本大小
function compareVersions(sVersion1,sVersion2){
    var aVersion1 = sVersion1.split(".");
    var aVersion2 = sVersion2.split(".");

JS 实现浏览器的 title 闪烁、滚动、声音提示、chrome、Firefox、Safari等系统通知。

    if(aVersion1.length>aVersion2.length){
        for(var i=0;i<aVersion1.length;i++)
            aVersion2.push("0");
    }else if(aVersion1.length<aVersion2.length){
        for(var i=0;i<aVersion2.length;i++)
            aVersion1.push("0");
    }

图片 1

    for(var i=0;i<aVersion1.length;i++){
        if(aVersion1[i]<aVersion2[i])
            return -1;
        else if(aVersion1[i]>aVersion2[i])
            return 1;
    }
    return 0;
};

下载

//检测是否Opera浏览器
var isOpera = sUserAgent.indexOf("Opera")>-1;
var isMinOpera4 = isMinOpera5 = isMinOpera6 = isMinOpera7 = isMinOpera7_5 = false;
if(isOpera){
    var fOperaVersion;
    if(navigator.appName == "Opera"){
        fOperaVersion = fAppVersion;
    } else {
        var reOperaVersion = new RegExp("Opera ()");
        reOperaVersion.test(sUserAgent);
        fOperaVersion = parseFloat(RegExp["$1"]);
    }

$ npm install title-notify --save-dev
$ bower install inotify --save-dev

    isMinOpera4 = fOperaVersion >= 4;
    isMinOpera5 = fOperaVersion >= 5;
    isMinOpera6 = fOperaVersion >= 6;
    isMinOpera7 = fOperaVersion >= 7;
    isMinOpera7_5 = fOperaVersion >= 7.5;
};

编译

//检测是否Safari
var isKHTML = sUserAgent.indexOf("KHTML")>-1
                || sUserAgent.indexOf("Konqueror")>-1
                || sUserAgent.indexOf("AppleWebKit")>-1;

# 下载依赖工具
$ npm install 
# 压缩inotify
$ npm build
init
effect: flash | scroll | favicon
var iNotify = new iNotify().init()
//推荐下面写法
var iNotify = new iNotify({
 message: '有消息了。',//标题
 effect: 'flash', // flash | scroll 闪烁还是滚动
 openurl:"http://www.bing.com", // 点击弹窗打开连接地址
 onclick:function(){ //点击弹出的窗之行事件
  console.log("---")
 },
 //可选播放声音
 audio:{
  //可以使用数组传多种格式的声音文件
  file: ['msg.mp4','msg.mp3','msg.wav']
  //下面也是可以的哦
  //file: 'msg.mp4'
 },
 //标题闪烁,或者滚动速度
 interval: 1000,
 //可选,默认绿底白字的 Favicon
 updateFavicon:{
  // favicon 字体颜色
  textColor: "#fff",
  //背景颜色,设置背景颜色透明,将值设置为“transparent”
  backgroundColor: "#2F9A00" 
 },
 //可选chrome浏览器通知,默认不填写就是下面的内容
 notification:{
  title:"通知!",//设置标题
  icon:"",//设置图标 icon 默认为 Favicon
  body:'您来了一条新消息'//设置消息内容
 }
})

var isMinSafari1 = isMinSafari1_2 = false;
var isMinKonq2_2 = isMinKonq3 = isMinKonq3_1 = isMinKonq3_2 = false;
if(isKHTML){
    isSafari = sUserAgent.indexOf("AppleWebKit")>-1;
    isKonq = sUserAgent.indexOf("Konqueror")>-1;
    if(isSafari){
        var reAppleWebKit = new RegExp("AppleWebKit\/()");
        reAppleWebKit.test(sUserAgent);
        var fAppleWebKitVersion = parseFloat(RegExp["$1"]);
       
        isMinSafari1 = fAppleWebKitVersion >= 85;
        isMinSafari1_2 = fAppleWebKitVersion >= 124;
    } else if (isKonq) {
        var reKonq = new RegExp("Konqueror\/()");
        reKonq.test(sUserAgent);
        isMinKonq2_2 = compareVersions(RegExp["$1"],"2.2") >= 0;
        isMinKonq3 = compareVersions(RegExp["$1"],"3.0") >= 0;
        isMinKonq3_1 = compareVersions(RegExp["$1"],"3.1") >= 0;
        isMinKonq3_2 = compareVersions(RegExp["$1"],"3.2") >= 0;
    }
};

isPermission

//检测IE
var isIE = sUserAgent.indexOf("compatible") > -1
            &&sUserAgent.indexOf("MSIE") > -1
            &&!isOpera;

判断浏览器弹框通知是否被阻止。

var isMinIE4 = isMinIE5 = isMinIE5_5 = isMinIE6 = isMinIE7 = false;
if(isIE){
    var reIE = new RegExp("MSIE ();");
    reIE.test(sUserAgent);
    var fIEVersion = parseFloat(RegExp["$1"]);
   
    isMinIE4 = fIEVersion >=4;
    isMinIE5 =  fIEVersion >=5;
    isMinIE5_5 = fIEVersion >=5.5;
    isMinIE6 = fIEVersion >=6;
    isMinIE7 = fIEVersion >=7;
};

iNotify.isPermission()

//检测Firfox
var isFF = sUserAgent.indexOf("Firefox")>-1&&!isKHTML;
var isMinFF1 = isMinFF2 =isMinFF3 = false;
if(isFF){
    var reFF = new RegExp("Firefox\/()");
    reFF.test(sUserAgent);
    isMinFF1 = compareVersions(RegExp["$1"],"1.0") >=0;
    isMinFF2 = compareVersions(RegExp["$1"],"2.0") >=0;
    isMinFF3 = compareVersions(RegExp["$1"],"3.0") >=0;
};

声音设置

//检测Mozilla
var isMoz = sUserAgent.indexOf("Gecko")>-1&&!isKHTML;
var isMinMoz1 = isMinMoz1_4 = isMinMoz1_5 = isMinMoz1_8 = false;
if(isMoz){
    var reMoz = new RegExp("rv:()");
    reMoz.test(sUserAgent);
    isMinMoz1 = compareVersions(RegExp["$1"],"1.0") >=0;
    isMinMoz1_4 = compareVersions(RegExp["$1"],"1.4") >=0;
    isMinMoz1_5 = compareVersions(RegExp["$1"],"1.5") >=0;
    isMinMoz1_8 = compareVersions(RegExp["$1"],"1.8") >=0;
};

player

var isNS4 = !isIE&&!isOpera&&!isMoz&&!isKHTML
            &&(sUserAgent.indexOf("Mozilla")==0)
            &&(navigator.appName == "Netscape")
            &&(fAppVersion >= 4.0 && fAppVersion <5.0);
var isMinNS4 = isMinNS4_5 = isMinNS4_7 =isMinNS4_8 = false;

播放声音

if(isNS4){
    isMinNS4 = true;
    ifMinNS4_5 = fAppVersion >= 4.5;
    ifMinNS4_7 = fAppVersion >= 4.7;
    ifMinNS4_8 = fAppVersion >= 4.8;
};

iNotify.player()
loopPlay

//检测Chrome浏览器
var isChrome = sUserAgent.indexOf("AppleWebKit")>-1;

自动播放声音

//检测操作系统
var isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows");
var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC")
            || (navigator.platform == "Macintosh");

iNotify.loopPlay()
stopPlay

var isUnix = (navigator.platform == "X11" && !isWin && !isMac);

停止播放声音

var isWin95 = isWin98 = isWinNT4 = isWin2K = isWinME = isWinXP = isWin2K3 = isVista = false;
var isMac68K = isMacPPC = false;
var isSunOS = isMinSunOS4 = isMinSunOS5 = isMinSunOS5_5 = false;
var isLinux = (navigator.platform == "Linux i686" && !isWin && !isMac);

iNotify.stopPlay()
setURL

//Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506)
if(isWin) {
    isWin95 = sUserAgent.indexOf("Win95") > -1 || sUserAgent.indexOf("Windows 95") >-1;
    isWin98 = sUserAgent.indexOf("Win98") > -1 || sUserAgent.indexOf("Windows 98") >-1;
    isWinME = sUserAgent.indexOf("Win 9x 4.90") > -1 || sUserAgent.indexOf("Windows ME") >-1;
    isWin2K = sUserAgent.indexOf("Windows NT 5.0") > -1 || sUserAgent.indexOf("Windows 2000") >-1;
    isWinXP = sUserAgent.indexOf("Windows NT 5.1") > -1 || sUserAgent.indexOf("Windows XP") >-1;
    isWin2K3 = sUserAgent.indexOf("Windows NT 5.2") > -1 || sUserAgent.indexOf("Windows 2003") >-1;
    //检测Vista系统可能有bug
    isVista = sUserAgent.indexOf("Windows NT 6.0") > -1 || sUserAgent.indexOf("Windows Vista") >-1;
    if(!isWin2K3&&!isVista){
        isWinNT4 = sUserAgent.indexOf("WinNT") > -1
                    || sUserAgent.indexOf("Windows NT") >-1
                    || sUserAgent.indexOf("WinNT4.0") >-1
                    || (sUserAgent.indexOf("Windows NT 4.0") >-1)
                    && (!isWinME&&!isWin2K&&!isWinXP);
    }
};

设置播放声音URL

if(isMac) {
    isMac68K = sUserAgent.indexOf("Mac_68000") > -1 || sUserAgent.indexOf("68K") > -1;
    isMacPPC = suserAgent.indexOf("MacPowerPC") > -1 || sUserAgent.indexOf("PPC") > -1;
};

iNotify.setURL('msg.mp3')// 设置一个
iNotify.setURL(['msg.mp3','msg.ogg','msg.mp4']) // 设置多个

if(isUnix) {
    isSunOS = sUserAgent.indexOf("SunOS") > -1;
    if(isSunOS){
        var reSunOS = new RegExp("SunOS ()");
        reSunOS.test(sUserAgent);
        isMinSunOS4 = compareVersions(RegExp["$1"],"4.0") >= 0;
        isMinSunOS5 = compareVersions(RegExp["$1"],"5.0") >= 0;
        isMinSunOS5_5 = compareVersions(RegExp["$1"],"5.5") >= 0;
    }
};

title通知

document.write("<br/>");
document.write("IE 浏览器:" + isIE);
document.write("<br/>");
document.write("Firfor 浏览器:" + isFF);
document.write("<br/>");
document.write("Windows 操作系统:" + isWin);
document.write("<br/>");
document.write("<br/>");
document.write("Mozilla 1.5 ↑:" + isMinMoz1_5);
document.write("<br/>");
document.write("Mozilla 1.8 ↑:" + isMinMoz1_8);
document.write("<br/>");
document.write("Firfox 1.0 ↑:" + isMinFF1);
document.write("<br/>");
document.write("Firfox 2.0 ↑:" + isMinFF2);
document.write("<br/>");
document.write("Firfox 3.0 ↑:" + isMinFF3);
document.write("<br/>");
document.write("Chrome:" + isChrome);
document.write("<br/>");
document.write("IE 4.0 ↑:" + isMinIE4);
document.write("<br/>");
document.write("IE 5.0 ↑:" + isMinIE5);
document.write("<br/>");
document.write("IE 5.5 ↑:" + isMinIE5_5);
document.write("<br/>");
document.write("IE 6.0 ↑:" + isMinIE6);
document.write("<br/>");
document.write("IE 7.0 ↑:" + isMinIE7);
document.write("<br/>");
document.write("Windows 95:" + isWin95);
document.write("<br/>");
document.write("Windows 98:" + isWin98);
document.write("<br/>");
document.write("Windows ME:" + isWinME);
document.write("<br/>");
document.write("Windows NT:" + isWinNT4);
document.write("<br/>");
document.write("Windows 2000:" + isWin2K);
document.write("<br/>");
document.write("Windows XP:" + isWinXP);
document.write("<br/>");
document.write("Windows 2003:" + isWin2K3);
document.write("<br/>");
document.write("Windows Vista:" + isVista);
document.write("<br/>");
document.write("Linux:" + isLinux);
document.write("<br/>");
document.write("Unix:" + isUnix);
document.write("<br/>");

最新的版本默认不播放标题闪烁动画,初始化之后需要调用 setTitle(true) 方法才播放标题动画。

作者“brian.netmad的博客”

setTitle

sUserAgent = navigator.userAgent; var fAppVersion = parseFloat(navigator.appVersion); //比较浏览器版本大小 function compareVersions(sVersion1,sVersion2){ var aVersion1...

设置标题,

iNotify.setTitle(true)//播放动画
iNotify.setTitle('新标题')//闪烁新标题
iNotify.setTitle()//清除闪烁 显示原来的标题
setInterval

 设置时间间隔

iNotify.setInterval(2000)
addTimer

添加计数器

iNotify.addTimer()
clearTimer

清除计数器

iNotify.clearTimer()

favicon通知

setFavicon

本文由美高梅游戏平台网站发布于 营养排行,转载请注明出处:Javascript检测系统信息各个浏览器信息

关键词:

上一篇:美高梅游戏平台网站HTTP 头部解释

下一篇:没有了

最火资讯