简体   繁体   English

如何在<= IE6上显示某些内容,在其他浏览器上显示不同的内容?

[英]How to show certain content to <=IE6 and different one to other browsers?

How to show certain content to IE6 + earlier versions and different one to the others? 如何在IE6 +早期版本中显示某些内容,而在其他版本中显示不同的内容? Is it possible with a conditional comment? 有条件注释是否可能?

Thanks 谢谢

UPDATE 更新

I can only edit a content within <body> tag... 我只能在<body>标签内编辑内容...

There is a better option described on Paul Irish blog. Paul Irish博客上描述了一个更好的选择。 ( Link here ) 链接在这里

The basic idea is to give class to your html tag like this. 基本思路是像这样将类赋予您的html标记。

<!--[if lt IE 7 ]> <html class="ie6"> <![endif]-->
<!--[if IE 7 ]>    <html class="ie7"> <![endif]-->
<!--[if IE 8 ]>    <html class="ie8"> <![endif]-->
<!--[if IE 9 ]>    <html class="ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html class=""> <!--<![endif]-->

Suppose there is a label in your page. 假设您的页面中有一个标签。 For example, 例如,

<label class="foo">Your browser is IE6!</label>

And you wanna display that label only in IE6, do this 而且您只想在IE6中显示该标签,请执行此操作

label.foo { display: none;}
.ie6 label.foo { display: block; }

This method sure has its pros and con s. 这种方法肯定有其优点和缺点

Please read all the other comments in the Paul Irish post for an in depth understanding of the scenario. 请阅读Paul Irish帖子中的所有其他评论,以深入了解该场景。

Indeed, the best part of a blog post often begins where the blog post ends. 实际上,博客文章的最佳部分通常始于博客文章的结尾。
Hope this helps. 希望这可以帮助。

You can use conditional comments to include content only for certain browsers 您可以使用条件注释来仅包含某些浏览器的内容

More info at: 有关更多信息,请访问:

http://www.quirksmode.org/css/condcom.html http://www.quirksmode.org/css/condcom.html

I'd recommend you to use ie-specific classes like HTML5 boilperplate do: 我建议您使用特定于ie的类,例如HTML5 boilperplate做:

<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en"> <![endif]-->
<!--[if IE 7]>    <html class="no-js ie7 oldie" lang="en"> <![endif]-->
<!--[if IE 8]>    <html class="no-js ie8 oldie" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->

Then you can have corresponding css to show/hide content, eg: 然后,您可以使用相应的CSS来显示/隐藏内容,例如:

.ie6-content: {visible: false;}
.ie6 .ie6-content: {visible: true;}
.content {visible: true;}
.ie6 .content {visible:false}

Thus sections with ie6-content will be visible for IE6 only, and section with content will not be visible in IE6. 因此,具有ie6-content部分仅在IE6中可见,而具有content部分在IE6中不可见。

Conditional comments (unfortunately) won't float your boat because they didn't exist until IE 5. Also, they weren't available on netscape. 有条件的注释(不幸的是)不会浮出水面,因为它们直到IE 5才存在。此外,它们在netscape上不可用。 Rather, simply, you put an iframe at the end of your content that displays your actual page contents like so. 而是简单地将iframe放在内容的末尾,以显示实际的页面内容。

<title>Your websites title</title>
<body style="margin:0px;font-size:0px;width:100%;height:100%;overflow:hidden">
    <h1>heading</h1>
    <p>Body paragraph</p>
    <!--[if gt IE 6]><!-->
    <iframe frameborder="0" width="100%" height="100%" src="main.html" style="position:relative;width:100%;height:100%;background-color:white"></iframe>
    <!--<![endif]-->
    <style language="css" type="text/css">/*<!--*/
        /* put your limited CSS here */
    /*-->*/</style>
</body>

Then, put in a downlevel revealed conditional comment so that the iframe doesn't show up on IE 6 or IE 5. Then, so long as the iframe doesn't have any text contents, it will be invisible in even the first version of the first internet browser. 然后,放入下层显示的条件注释,以使iframe不会出现在IE 6或IE 5上。然后,只要iframe没有任何文本内容,即使在第一个版本的iframe中也看不到它。第一个互联网浏览器。

Then, because no sane person would want to put in enough time, energy, and effort to provide compatibility with IE5 for an ordinary website, you can just use down-level revealed conditional comments (supported before iframes were supported thankfully). 然后,因为没有一个理智的人愿意投入足够的时间,精力和精力来为普通网站提供与IE5的兼容性,所以您可以使用下层显示的条件注释(感谢iframe的支持)。

Then, you can add in a little super-basic CSS for browsers like the oldest version of Netscape. 然后,您可以为浏览器(如最旧的Netscape版本)添加一些超基本CSS。 Super-basic CSS includes things like color and crop, and excludes things like just about everything cool and modern. 超基本CSS包括颜色和裁切之类的东西,并且不包括诸如酷炫和现代之类的东西。

My source for this is, of course, the source code for the world's first website. 我的源代码当然是世界上第一个网站的源代码。 The most complete bits can be found here: at cern . 可以在以下位置找到最完整的位: cern It is also the reason for putting the title outside of the head, and not including any head at all. 这也是将标题放在首位而不是完全不包括首位的原因。

SO, this method will allow you to display a plain alternative to the webpage to all browsers older than IE 6. You may then ask what about Chrome, Firefox, Opera, and other browsers. 因此,该方法将允许您在IE 6之前的所有浏览器上显示该网页的替代形式。然后,您可能会问Chrome,Firefox,Opera和其他浏览器如何。 Well, those browsers automatically update. 好吧,那些浏览器会自动更新。 So really, there is no real need to extend support to previous versions of them. 因此,实际上并不需要扩展对以前版本的支持。

At any rate, the above layout is sketcky at best, but hey: it workz. 无论如何,以上布局充其量是最好的,但是,嘿,它有效。 And, that is good enough for me. 而且,这对我来说已经足够了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何仅显示HTML - How Do I Show HTML Only In <IE6 Old Browsers 在IE6和其他浏览器下显示不同 - display different under IE6 and other browers 为什么我们需要针对不同浏览器使用不同的CSS,特别是在IE(IE6,IE7,8,9的差异)的情况下 - Why We need different CSS for different browsers specially in case of IE(diff for IE6, IE7, 8, 9) 如何检测IE6,并显示警报? - How to detect IE6, and show alert? 如何给DIV两个高度(一个用于IE,第二个用于其他浏览器) - how to give two heights to DIV (one for IE and second for other browsers) 2种不同的链接样式在IE中显示,但在其他浏览器中没有。 链接点击后,所有链接显示已访问 - 2 different link styles show ok in IE but not in other browsers. When link clicked all links show visited 使用IE10 +会显示这种方法 - With IE10+ would this method of showing <IE6 a jpg, and other browsers a png be an issue? Firefox,IE6和歌剧有不同的表现 - firefox , IE6 and opera have different things to show 导航栏在IE6、7、8中无法正常显示,但在9和所有其他浏览器上均可 - Navigation bar not displaying well in IE6,7,8 but works on 9 and all other browsers IE6,7,8,9在另一个div下方加载div,而其他浏览器将其加载到右侧 - IE6,7,8,9 loading div underneath another div while other browsers load it to the right
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM