开发者

Why are javascripts sometimes surrounded by these tags?

开发者 https://www.devze.com 2022-12-28 01:11 出处:网络
Why are some JavaScripts encapsulated within these tags: <!--//--><![CDATA[//>开发者_运维问答<!--

Why are some JavaScripts encapsulated within these tags:

<!--//--><![CDATA[//>开发者_运维问答<!--

some js here

//--><!]]>


<![CDATA[//> is to prevent XML parsers from choking on the script.

<!-- ... --> is not required unless you're using Netscape 1.0.

See: Does it still make sense to use HTML comments on blocks of JavaScript?


It makes it valid XHTML.


They were used for old browsers which didn't understand the <script> tag. That way if a browser didn't properly read the JavaScript, it would just render it as a comment and not show up on the page.

It also allows JavaScript code to be inside valid XHTML pages without having to escape characters which aren't valid in XML.

0

精彩评论

暂无评论...
验证码 换一张
取 消