在JavaScript块上使用HTML注释是否有意义? [英] Does it still make sense to use HTML comments on blocks of JavaScript?

查看:128
本文介绍了在JavaScript块上使用HTML注释是否有意义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去,人们习惯于围绕JavaScript块打包HTML注释标签,以防止旧浏览器显示脚本。即使Lynx聪明地忽略了JavaScript,那么为什么有些人会这样做呢?这些天是否有任何有效的原因?

 < script type =text / javascript> 
<! -
//某些js代码
// - >
< / script>

编辑:我遇到过一种情况。在设计视图中,某些代码编辑器(如Dreamweaver)在引用的JavaScript字符串中被混淆,并尝试将其显示为页面的一部分。 解决方案

不,绝对不是。任何用户代理,搜索引擎蜘蛛,或者这些天绝对的其他任何东西都足够聪明,可以忽略Javascript,如果它不能执行它的话。



只有很短的时间这完全有帮助,大概是1996年。

In the past people used to wrap HTML comment tags around blocks of JavaScript in order to prevent "older" browsers from displaying the script. Even Lynx is smart enough to ignore JavaScript, so why do some people keep doing this? Are there any valid reasons these days?

<script type="text/javascript">
<!--
//some js code
//-->
</script>

Edit: There is ONE situation I did encounter. Some code editors, such as Dreamweaver, get confused by quoted HTML inside a JavaScript string when in "design view" and try to display it as part of your page.

解决方案

No, absolutely not. Any user agent, search engine spider, or absolutely anything else these days is smart enough to ignore Javascript if it can't execute it.

There was only a very brief period when this was at all helpful, and it was around 1996.

这篇关于在JavaScript块上使用HTML注释是否有意义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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