What is the Best way to do Browser Detection in Javascript?

前端 未结 8 1842
自闭症患者
自闭症患者 2020-12-05 16:55

In one of my Web Development classes we where asked to create a script that detects NE4,NE6+,IE4,IE6+ Browsers that display a compatable CSS script for each browser.

8条回答
  •  生来不讨喜
    2020-12-05 17:25

    The standard way to detect what browser is used is to check the user agent supplied.

    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

    http://www.quirksmode.org/js/detect.html

提交回复
热议问题