IE 8 上渲染的 html 中出现奇怪的额外字符
我有一个 ASP.Net MVC 站点,我想在其中渲染一些自定义 HTML 5 画布。我遇到一个奇怪的问题,服务器提供源代码中没有的额外字符。
为了在 IE 8 中使用 HTML 5 画布,您必须在 html 头部添加以下标记:
<!--[if IE]><script src="../../Scripts/excanvas.js"></script><![endif]-->
由于某种原因,这被提供为:
<!--[if IE]>IE]><script src="../../Scripts/excanvas.js"></scr<![endif]-->
当然,duff 标记会导致 IE 不加载 excanvas 脚本。我不明白为什么该行会出现乱码。我有以下文档类型,记录在 http://www.w3schools.com/html5/tag_doctype 中。 asp:
<!DOCTYPE html>
我不熟悉使用 HTML 5 或新的文档类型,所以我对此表示怀疑。我也在 Apache 上使用 Mono 托管,所以也许这就是乱码的原因。
有问题的页面位于:http://openancestry.org/FamilyTree/Simpsons
任何人以前看过此内容或知道为什么我不能使用“if IE”语法吗?
更新: 嗯,我很确定是 Mono 或 Apache 弄乱了 HTML,所以我使用了下面的解决方法,它为 IE8 添加了兼容性元标记,并为 IE9 之前的任何 IE 包含了 excanvas。 我仍然希望得到有关 HTML 为何出现乱码的任何答案。
<% if (Request.Browser.Browser.Contains("IE") && float.Parse(Request.Browser.Version) < 9) { %>
<% if (float.Parse(Request.Browser.Version) > 7) { %>
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<% } %>
<script type="text/javascript" src="../../Scripts/excanvas.js"></script>
<% } %>
I have an ASP.Net MVC site that I want to render some custom HTML 5 canvasses in. I am getting a strange issue with the server serving up extra characters that are not in the source code.
In order to use an HTML 5 canvas in IE 8 you have to add the following tag in the html head:
<!--[if IE]><script src="../../Scripts/excanvas.js"></script><![endif]-->
For some reason this is served up as:
<!--[if IE]>IE]><script src="../../Scripts/excanvas.js"></scr<![endif]-->
Of course the duff markup causes the excanvas script to not be loaded by IE. I can't understand why the line gets garbled. I have the following doctype which is documented at http://www.w3schools.com/html5/tag_doctype.asp:
<!DOCTYPE html>
I'm not familiar with using HTML 5 or the new doctype so I'm suspicious of it. I'm also hosting on Apache with Mono so maybe that's what's garbling the line.
The page in question is at: http://openancestry.org/FamilyTree/Simpsons
Anyone seen this before or know why I cant use the "if IE" syntax?
UPDATE:
Well I'm pretty sure it's either Mono or Apache thats garbling the HTML so I've used the workaround below which adds a compatibility meta tag for IE8 and includes excanvas for any IE that predates IE9.
I'd still appreciate any answers on why the HTML gets garbled.
<% if (Request.Browser.Browser.Contains("IE") && float.Parse(Request.Browser.Version) < 9) { %>
<% if (float.Parse(Request.Browser.Version) > 7) { %>
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<% } %>
<script type="text/javascript" src="../../Scripts/excanvas.js"></script>
<% } %>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在回答之前,我想指出您的示例中缺少
type="text/javascript"
。Mono 中的 ASP.NET 解析器可能会破坏您的注释。你使用的是哪个版本的 Mono(我想是什么平台)。
我刚刚在 Mac 上的 Mono 2.10 上尝试过,没有遇到这个问题。
Before I answer, I want to point out that you are missing
type="text/javascript"
in your example.It is possible that the ASP.NET parser in Mono is mangling your comment. What version of Mono are you using (and what platform I suppose).
I just tried this on Mono 2.10 on Mac and did not have this problem.