设备浏览器检测

Device browser detection

本文关键字:检测 浏览器      更新时间:2023-09-26

我为一个客户端网站制作了一个视差介绍-由于预算有限,动画只能在高端浏览器IOS和ie9上运行。

因此,我需要在网站主页中创建一个检测脚本,它将检测以下

IF:

  • ie9/firefoxchrome/safari-留在当前网站
  • IOS-转到IOS版本
  • Android-跳转到主站点
  • IE8及以下版本-跳到主站点

我过去用PHP进行过"是移动的"检测,但上面的检测非常具体,所以我不知道如何处理它。主网站是aspx,所以我也可以将动画页面制作成aspx页面,并使用服务器端检测,或者查看Javascript/jquery选项或插件,或者两者结合。。?

有人能推荐一个好的解决方案吗?

希望不要进入浏览器检测/feauture检测的争论等等,http://www.quirksmode.org/js/detect.html有一个很好的脚本来处理这个

尝试使用以下代码,使用navigator对象::

    var ua = navigator.userAgent;
    if(navigator.appName == "Netscape"){ //for Firefox, Safari and Chrome
         //do nothing, stay on this page.
         return;
    }
    else if(navigator.appName == 'Microsoft Internet Explorer'){
        //check for version
        var re  = new RegExp("MSIE ([0-9]{1,}['.0-9]{0,})");
        if (re.exec(ua) != null){
          version = parseFloat( RegExp.$1 );
        }
        if(version >= 9.0){
           //do nothing, stay on this page.
           return;
        }
        else{
           //redirect to the site for lower IE versions.
        }
    }
    else if(ua.match(/Android/i)){
       //code for skipping to Android version
    }
    else if(ua.match(/iPhone/i)){
       //code for skipping to iPhone version
    }
    else if(ua.match(/iPad/i)){
       //code for skipping to iPad version
    }

有一个JQuery对象$.browser,它可以在javascript中为您提供所需的东西,这里是api调用。

在服务器端有一个.net请求。浏览器对象也是它的MSDN Api。