什么时候是“javascript:...”需要? [英] When is "javascript: ..." needed?
问题描述
真的需要 javascript:
前缀吗?我知道你的目标应该是不引人注目的JavaScript,但在什么情况下如果它不存在会破坏?
Is the javascript:
prefix really needed? I know you should aim for unobtrusive JavaScript but under what circumstances would something break if it is not there?
推荐答案
javascript:
是一个URI方案。
需要创建一个运行Javascript的URI,在 href =
属性或在浏览器地址栏中。
从来没有 javascript:
的情况可选。
It is needed to create a URI that runs Javascript, either in an href=""
attribute or in the browser address bar.
There is never a situation in which javascript:
is optional.
最佳做法表明 javascript:
应尽可能避免使用URI,以支持点击
处理程序,因此不赞成使用它。
Best practices indicate that javascript:
URIs should be avoided where possible in favor of click
handlers, so its use is frowned upon.
但是,有些情况下没有其他选择。例如,只能使用 javascript:
创建bookmarklet。
However, there are cases where there is no alternative. For example, bookmarklets can only be created by using javascript:
.
这篇关于什么时候是“javascript:...”需要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!