dt56449492 2014-07-03 14:58
浏览 23

检测浏览器类型并应用相关样式

I've built a “in-house” web application for my company mainly using PHP/MySQL that’s in use in a few departments in my company.

I styled the site (I suppose naively) so that it would work well and look good using Chrome and Firefox. Until recently this wasn’t a problem as everyone using it was using those browsers.

However, a new department has been added to the list of users and they all use an old version of IE and they don’t have permissions to upgrade or install any software on their own machines. I found one or two issues but not many as a result.

I want to be able to detect what browser someone is using and apply a particular styling accordingly.

I'm not the best at JavaScript but I suppose that would be how it's done? But how?

  • 写回答

5条回答 默认 最新

  • douchu4048 2014-07-03 15:01
    关注

    You may be looking for something like:

        var navigator = function (){
            var ua= navigator.userAgent, tem, 
            M= ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*([\d\.]+)/i) || [];
            if(/trident/i.test(M[1])){
                tem=  /\brv[ :]+(\d+(\.\d+)?)/g.exec(ua) || [];
                return 'IE '+(tem[1] || '');
            }
            M= M[2]? [M[1], M[2]]:[navigator.appName, navigator.appVersion, '-?'];
            if((tem= ua.match(/version\/([\.\d]+)/i))!= null) M[2]= tem[1];
            return M.join(' ');
        };
    //usage
    //IE < 10
            if(navigator()[0] == "I" && navigator().match(/\d+/) < 10){
                alert('You are using '+navigator+'.Please update to version >= 10');
            }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记