判断各浏览器

Posted 陌凌雪

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了判断各浏览器相关的知识,希望对你有一定的参考价值。

function Browser() {
    this.Opera = window.opera ? true : false;
    this.IE = document.all && !this.Opera ? true : false;
    this.IE6 = this.IE && typeof(window.XMLHttpRequest) == "undefined" ? true : false;
    this.IE8 = this.IE && typeof(document.querySelectorAll) != "undefined" ? true : false;
    this.IE7 = this.IE && !this.IE6 && !this.IE8 ? true : false;
    this.WebKit = /WebKit/i.test(navigator.userAgent) ? true : false,
        this.iPhone = /iPhone|iPod/i.test(navigator.userAgent) ? true : false;
    this.Chrome = /Chrome/i.test(navigator.userAgent) ? true : false;
    this.Safari = /Safari/i.test(navigator.userAgent) && !this.Chrome ? true : false;
    this.Konqueror = navigator.vendor == "KDE" ? true : false;
    this.Konqueror4 = this.Konqueror && /native code/.test(document.getElementsByClassName) ? true : false;
    this.Gecko = !this.WebKit && navigator.product == "Gecko" ? true : false;
    this.Gecko19 = this.Gecko && Array.reduce ? true : false;
    this.toString = "Opera=" + this.Opera + ",IE=" + this.IE + ",IE6=" + this.IE6 + ",IE7=" + this.IE7 + ",IE8=" + this.IE8 + ",Chrome=" + this.Chrome;
}

 

以上是关于判断各浏览器的主要内容,如果未能解决你的问题,请参考以下文章

兼容ie8,firefox,chrome浏览器的代码片段

判断各浏览器

Android 事件分发事件分发源码分析 ( Activity 中各层级的事件传递 | Activity -> PhoneWindow -> DecorView -> ViewGroup )(代码片段

各浏览器鼠标滚轮事件

JavaScript判断IE各版本最完美解决方案

ajax中基本兼容各浏览器的XMLHttpRequest的创建