如何显示浏览器特定的HTML? [英] How to display browser specific HTML?

查看:119
本文介绍了如何显示浏览器特定的HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一种方法来显示一个链接到一个IE用户和另一个链接到所有其他浏览器使用JavaScript或条件注释(或任何需要)。



基本上...

  //伪代码
<! - [if IE]>
< a hrefie-only.html>点击此处!< / a>
<! - [else]>
< a hrefall-other-browsers.html>点击此处!< / a>
<![endif] - >

我不认为使用条件注释标记(仅适用于Internet Explorer)是不可能的。另外我不认为有一个其他的声明。



有没有办法用javascript做到这一点?请帮忙!谢谢!

解决方案


我不认为这是可能的条件注释标签在Internet Explorer中)


确实如此。您只需将非IE浏览器的内容保留在某个位置,使其成为条件注释子句的一部分,但实际上并不在<! - comment - >内。然后,不知道条件注释的浏览器会看到内容正常。这被称为下层级显示有条件的评论。

不幸的是,微软给你的标记是无效的HTML(甚至没有格式良好的XML)。要让它通过,你只需要一些额外的' - ':

 <! -  [if IE] >这是IE!百分比抑制率ENDIF]  -  GT!; 
<! - [if!IE]><! - >这不是IE! <! - <![ENDIF] - GT;

尽管我必须回应AnonJr的非答案,但很少见,您应该需要一个完全独立的链接/ IE浏览器相比,其他浏览器。如果你在IE中使用复杂的VML和ActiveX工作,在其他浏览器上使用Flash,我想这可能是有原因的,但通常在同一个基本页面上的一些CSS和脚本攻击就足够了。


I'm trying to find a way to display one link to an IE user and another link to all other browsers using javascript or conditional comments (or whatever it takes).

Basically...

//pseudo code
<!--[if IE]>
    <a href"ie-only.html">click here!</a>
<!--[else]>
    <a href"all-other-browsers.html">click here!</a>
<![endif]-->

I don't think this is possible with conditional comment tags (which only work in internet explorer). Plus I don't think there is an "else" statement.

Is there a way to do this with javascript? Please help! Thanks!

解决方案

I don't think this is possible with conditional comment tags (which only work in internet explorer)

Sure it is. You just have to leave the content for non-IE browsers in a position such that it's part of a conditional comment clause but not actually inside a <!-- comment -->. Then browsers that don't know about conditional comments will see the content fine. This is known as a downlevel-revealed conditional comment.

Unfortunately the markup Microsoft give you there is invalid HTML (and not even well-formed XML). To make it pass muster you just need a few additional ‘--’s:

<!--[if IE]> This is IE! <![endif]-->
<!--[if !IE]><!--> This ain't IE! <!--<![endif]-->

Although I have to echo AnonJr's non-answer, in that it's rare you should need a completely separate link/page for IE compared to other browsers. If you're doing something tricky like complex VML and ActiveX work in IE with Flash on other browsers I guess there could be a reason for it, but usually a few CSS and script hacks over the same basic page should suffice.

这篇关于如何显示浏览器特定的HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆