脚本中的双连字符使firefox奇怪地呈现 [英] double hyphen in script makes firefox render strangely

查看:256
本文介绍了脚本中的双连字符使firefox奇怪地呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <! - < script type =text / javascript> / *<![CDATA [* / c--; //]]& ; / script> - > 

当我在< head>部分的一个纯HTML页面,Firefox 3.5.5呈现尾随 - >作为文本。如果我改变c--到c-它不。任何想法在这里发生了什么?我在我的页面上有一个工件,因为一个非常大的脚本已经嘎吱嘎吱。我可以改变语句为c- = 1,避免现在的问题,但....我想知道什么位/字节咬我的a $$。

解决方案

这是由于Firefox实现了SGML(基于HTML)。这将只会发生在文档以标准模式加载(即有一个DOCTYPE)。



第一个<!开始注释。第一个 - 输入允许使用> 字符的部分。第二个 - (在脚本中)留下允许使用> 字符的部分。 < / script> 结尾处的> 因此,以下 - > 不再是注释的一部分,并以文本形式呈现。



http://www.howtocreate.co.uk/SGMLComments.html 公开综合指南。



它还值得注意的是 HTML 4规范说,作者应避免在注释中插入两个或更多个连字符和 HTML 5规格说明注释不得包含两个连续的U + 002D HYPHEN-MINUS字符( - )'。 / p>

您发现的解决方案是在注释中不包括 - 。 / p>

<!-- <script type="text/javascript">/*<![CDATA[*/  c-- ;//]]></script> -->

When I have the above line in the <head> section of a plain html page, Firefox 3.5.5 renders the trailing --> as text. If I change c-- to c- it doesn't. Any ideas what's going on here? I getting an artifact on my pages with this due to a very large script that's been crunched. I can change the statement to c-=1 and avoid the problem for now but.... I'd like to know what bit/byte is biting my a$$.

解决方案

This is due to Firefox implementing SGML (on which HTML was based) comments strictly. This will only occur when the document is loaded in standards mode (i.e. there is a DOCTYPE).

The first <! starts a comment. The first -- enters a section in which > characters are allowed. The second -- (in your script) leaves the section in which > characters are allowed. The > at the end of </script> then ends the comment. The following --> is therefore no longer part of the the comment and gets rendered as text.

See http://www.howtocreate.co.uk/SGMLComments.html for a fairly comprehensive guide to the issue.

Its also worth noting that the HTML 4 Specification says that 'authors should avoid putting two or more adjacent hyphens inside comments' and the HTML 5 Specification says comments must not 'contain two consecutive U+002D HYPHEN-MINUS characters (--)'.

The solution, as you've found, is to not include -- in the middle of a comment.

这篇关于脚本中的双连字符使firefox奇怪地呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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