博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Javascript 浏览器检测
阅读量:5272 次
发布时间:2019-06-14

本文共 3418 字,大约阅读时间需要 11 分钟。

推荐 Browser Detecter, 很好用,自己也很容易扩展。 原文链接:

    

BrowserDetecter.js

var BrowserDetect = {    init: function () {        this.browser = this.searchString(this.dataBrowser) || "An unknown browser";        this.version = this.searchVersion(navigator.userAgent)            || this.searchVersion(navigator.appVersion)            || "an unknown version";        this.OS = this.searchString(this.dataOS) || "an unknown OS";    },    searchString: function (data) {        for (var i = 0; i < data.length; i++) {            var dataString = data[i].string;            var dataProp = data[i].prop;            this.versionSearchString = data[i].versionSearch || data[i].identity;            if (dataString) {                if (dataString.indexOf(data[i].subString) != -1)                    return data[i].identity;            }            else if (dataProp)                return data[i].identity;        }    },    searchVersion: function (dataString) {        var index = dataString.indexOf(this.versionSearchString);        if (index == -1) return;        return parseFloat(dataString.substring(index + this.versionSearchString.length + 1));    },    dataBrowser: [        {            string: navigator.userAgent,            subString: "Chrome",            identity: "Chrome"        },        {            string: navigator.userAgent,            subString: "OmniWeb",            versionSearch: "OmniWeb/",            identity: "OmniWeb"        },        {            string: navigator.vendor,            subString: "Apple",            identity: "Safari",            versionSearch: "Version"        },        {            prop: window.opera,            identity: "Opera",            versionSearch: "Version"        },        {            string: navigator.vendor,            subString: "iCab",            identity: "iCab"        },        {            string: navigator.vendor,            subString: "KDE",            identity: "Konqueror"        },        {            string: navigator.userAgent,            subString: "Firefox",            identity: "Firefox"        },        {            string: navigator.vendor,            subString: "Camino",            identity: "Camino"        },        {        // for newer Netscapes (6+)            string: navigator.userAgent,            subString: "Netscape",            identity: "Netscape"        },        {            string: navigator.userAgent,            subString: "MSIE",            identity: "Explorer",            versionSearch: "MSIE"        },        {            string: navigator.userAgent,            subString: "Gecko",            identity: "Mozilla",            versionSearch: "rv"        },        {         // for older Netscapes (4-)            string: navigator.userAgent,            subString: "Mozilla",            identity: "Netscape",            versionSearch: "Mozilla"        }    ],    dataOS: [        {            string: navigator.platform,            subString: "Win",            identity: "Windows"        },        {            string: navigator.platform,            subString: "Mac",            identity: "Mac"        },        {            string: navigator.userAgent,            subString: "iPhone",            identity: "iPhone/iPod"        },        {            string: navigator.platform,            subString: "Linux",            identity: "Linux"        }    ]};BrowserDetect.init();

转载于:https://www.cnblogs.com/Dannier/p/3234132.html

你可能感兴趣的文章
Redis的安装与使用
查看>>
P1970 花匠
查看>>
java语言与java技术
查看>>
NOIP2016提高A组五校联考2总结
查看>>
iOS 项目的编译速度提高
查看>>
table中checkbox选择多行
查看>>
Magento开发文档(三):Magento控制器
查看>>
性能调优攻略
查看>>
ie6解决png图片透明问题
查看>>
瞬间的永恒
查看>>
2019-8-5 考试总结
查看>>
JS中实现字符串和数组的相互转化
查看>>
web service和ejb的区别
查看>>
Windows Azure Cloud Service (29) 在Windows Azure发送邮件(下)
查看>>
CS61A Efficiency 笔记
查看>>
ArcGIS Server Javascript 多图对比功能
查看>>
微信上传素材返回 '{"errcode":41005,"errmsg":"media data missing"}',php5.6返回
查看>>
div或者p标签单行和多行超出显示省略号
查看>>
Elasticsearch 滚动重启 必读
查看>>
Hadoop基本概念
查看>>