dqed19166 2011-02-07 22:43
浏览 68
已采纳

使用PHP测试IE

I am developing a web page that will be used in several different contexts, and while I normally avoid browser sniffing and conditional statements at all costs, there is just no way around it this time.

I'm trying a simple method, and I was hoping I could get some feedback on whether this is a good idea or not.

I am testing for the user agent and then echoing a class on the element in the html (in my case, a div) if the user agent is IE.

<?php echo (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'msie') !== FALSE) ? ('classforie') : (''); ?>

Then in my css, I am doing something along the lines of this;

.classone { display: inline-block; }
.classone.classforie { zoom: 1; display: inline; }

Note, the CSS isn't the important part, I just made that up for the sake of example. I'm just wondering if doing things this way is a good practice or not?

  • 写回答

2条回答 默认 最新

  • dqpdb82600 2011-02-07 22:46
    关注

    No. Use conditional comments. User agent sniffing is unreliable.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度