dousikuai5417 2014-06-04 17:37 采纳率: 0%
浏览 37

如何识别IE8及以下版本以发布唯一代码?

I'm intending to place some code into the header of my CMS that will alert any users who are using IE 8 and below, suggesting to upgrade their browser.

In PHP, I've got the following code, and it shows for ALL versions of IE.

<?php
    if(preg_match('/(?i)msie [1-8]/',$_SERVER['HTTP_USER_AGENT'])) {
        // if IE<=8
        ?>
            <!--[if lte IE 8]>
            <div class="ieNotice">
                <a href="http://windows.microsoft.com/en-us/internet-explorer/" target="_blank">
                    <img src="/skin/frontend/default/hellowired/images/ieUpgrade.jpg">
                </a>
            </div>
            <style>
                .ieNotice {
                    background-color: #eee;
                    padding: 10px;
                }
            </style>
            <![endif]-->
        <?php
    }
?>

This SHOULD work two fold. One, the $_SERVER['HTTP_USER_AGENT']) should be able to tell the browsers apart. However, I'm noticing that when I run cross browser testing, IE 8 and UP are coming back with the same result for $_SERVER['HTTP_USER_AGENT']), which is:

Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)

OK... even if that didn't work... wouldn't the "Quirks Mode" conditional comments be there as a fallback to only show the image and link to IE8 and below? What am I missing here?

EDIT

OK, so I have done as instructed. I have removed the PHP code, and placed the .ieNotice class with the display: none property. Now, on the stylesheet that is included here:

<!--[if lte IE 8]>
<link rel="stylesheet" type="text/css" href="/skin/frontend/default/hellowired/css/styles-ie-lte8.css" media="all" />
<![endif]-->

I have added the following line:

.ieNotice { display: block !important;}

I have seen this work on Firefox and Chrome properly, but it is still showing the banner I've created for IE 9, 10 & 11.

  • 写回答

3条回答 默认 最新

  • dongniaocheng3773 2014-06-04 17:39
    关注

    You shouldn't rely on a user agent string, that can be spoofed by users. Especially since you are already using <!--[if lte IE 8]>, which will only show up on IE <= 8. I'd get rid of the PHP conditional altogether.

    评论

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制