【问题标题】:Detect the Browser and show a other content检测浏览器并显示其他内容
【发布时间】:2012-09-23 07:19:45
【问题描述】:

我只使用 CSS3 和 HTML5 构建网站。 所以IE不能正确显示。 我想向每个 Internet Explorer 用户展示一个内容简单的其他网站:请使用现代浏览器,例如 Google Chrome、Fire Fox ...

如何检测浏览器并显示其他网站? 或者我可以为 Internet Explorer 用户构建一个文本,例如

<div style="display:none;">Please use a modern Browser!</div>

只为 Internet Explorer 用户显示?

【问题讨论】:

  • IE 支持 CSS 3 和 HTML 5 的合理子集。
  • 你搜索过互联网检测IE吗?更好的是嗅探你使用的东西的支持。看modernizr.com
  • 大多数看到此类消息的人要么无法改变,要么不愿意改变。
  • 内容为王。演示文稿可能会降级,但它应该这样做gracefully。这不是让人们离开网站的理由。
  • 希望用户切换浏览器只是为了访问一个网站可能有点乐观。

标签: javascript html css internet-explorer


【解决方案1】:

您可以利用 IE 检测到 IE 本身输出。因此,将 div 放置为无显示,然后制作一个 ie 样式表并定位您想要的所有不同版本。

更多详情请点击此处:http://css-tricks.com/how-to-create-an-ie-only-stylesheet/

【讨论】:

  • 很高兴为您提供帮助!如果您不介意选择它作为您的官方答案(如果结果对您很好!),我将不胜感激!
【解决方案2】:

navigator.userAgent

这里有一个很酷的脚本:http://www.quirksmode.org/js/detect.html

【讨论】:

    【解决方案3】:

    您可以使用以下内容:

    <?php
    $u_agent = $_SERVER['HTTP_USER_AGENT']; 
    if(preg_match('/MSIE/i', $u_agent)) 
    { 
        // Change http://www.othersite.com, by your other site URL
        header('Location: http://www.othersite.com'); 
    } 
    ?>
    

    您还可以对 IE 使用条件 cmets。

    【讨论】:

    • php 标签在哪里? :)
    【解决方案4】:

    有更好的选择,而不是添加新的样式表

    <!doctype html>
    <!--[if lt IE 7 ]> <html class="ie ie6" lang="en-US"> <![endif]-->
    <!--[if IE 7 ]> <html class="ie ie7" lang="en-US"> <![endif]-->
    <!--[if IE 8 ]> <html class="ie ie8" lang="en-US"> <![endif]-->
    <!--[if IE 9 ]> <html class="ie ie9" lang="en-US"> <![endif]-->
    <!--[if gt IE 9]><!-->
    <html lang="en-US">
    <!--<![endif]-->
    

    在样式表中只为选择器添加一个类

    .page {
        //some style for morden browsers
    }
    .ie .page {
        //some style for all ie versions
    }
    .ie6 .page {
        //some style for ie 6 only
    }
    .ie7 .page {
        //some style for ie 7 only
    }
    .ie8 .page {
        //some style for ie 8 only
    }
    .ie9 .page {
        //some style for ie 9 only
    }
    

    这将使用单个样式表完成

    【讨论】:

      猜你喜欢
      • 2012-01-15
      • 1970-01-01
      • 1970-01-01
      • 2012-08-25
      • 1970-01-01
      • 2021-07-06
      • 1970-01-01
      • 1970-01-01
      • 2014-11-05
      相关资源
      最近更新 更多