什么是隐藏IE8用户的所有内容的最佳方法

时间:2015-02-21 20:48:40

标签: javascript php jquery html wordpress

所以我知道我可以在我的所有帖子和其他内容上display:none;

问题在于你无论如何都可以看到源代码中的内容(非常确定99.9999%的IE8用户甚至不知道源代码选项,但是想要将其隐藏在源代码中... )。 我想要做的是除了在页面和源代码中显示类似的内容之外,根本不会得到任何代码:

<!--[if lte IE 8]>
    <h2>You should update your browser version or choose another. Otherwise the content will not be visible for Internet Explorer users or below.<h2>
<![endif]-->

(这是一个WordPress网站)

3 个答案:

答案 0 :(得分:1)

警告:警惕使用Jack Zelig的上述答案,它会损害服务器的安全性,因为它在解析用户代理的函数上运行eval。可以通过在服务器上运行代码来利用用户可访问的eval()。

This question has been answered more thoroughly here

if (preg_match('/MSIE\s(?P<v>\d+)/i', @$_SERVER['HTTP_USER_AGENT'], $B) && $B['v'] <= 8) {
    // Browsers IE 8 and below
    // Don't render regular template files to these users
    // e.g.: include 'update-your-browser.php'
} else {
    // All other browsers
    // Offer a version of the regular site
}

其他类似的解决方案可以改编: Can I detect IE6 with PHP?

Sidenote: also, avoid using /e on regular expressions since it will also evaluate any code included on whatever you are parsing.

答案 1 :(得分:0)

简短的回答是肯定的,可以做到。

但是对于你所描述的内容,我会说你不应该担心人们在你的源代码中看到的内容,除非这是一个安全问题(在这种情况下,它应该对每个人都隐藏,可能能够看到它的各种技术)。表示层对访问者来说真的很重要,在这种情况下display:none就足够了。

答案 2 :(得分:0)

在主题文件夹的index.php中尝试:

<?php
function iever($compare=false, $to=NULL){
    if(!preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $m)
     || preg_match('#Opera#', $_SERVER['HTTP_USER_AGENT']))
        return false === $compare ? false : NULL;

    if(false !== $compare
        && in_array($compare, array('<', '>', '<=', '>=', '==', '!=')) 
        && in_array((int)$to, array(5,6,7,8,9,10))){
        return eval('return ('.$m[1].$compare.$to.');');
    }
    else{
        return (int)$m[1];
    }
}

if(iever('<=', 8)){ 
  <?php include (TEMPLATEPATH . '/shared/header.php' ); ?>
  <!-- YOUR CONTENT -->
  <?php 
    include (TEMPLATEPATH . '/shared/sidebar.php' );
    include (TEMPLATEPATH . '/shared/footer.php' ); 
  ?>
} else {
  echo("Oh noes. IE8 or below. Maybe");
}

如果有效,请在评论中告诉我,我会找出要挂钩的动作(可能是init?),以便可以为每个页面完成。

我从here获得了浏览器嗅探功能。

你知道浏览器嗅探很糟糕,对吗?

相关问题