[英]Why don't browsers throw an error when any other word is used in place of 'javascript' in the value of onclick?
I inherited a website, and just came across this curiosity: 我继承了一个网站,只是遇到了这种好奇心:
<a href="/delete" onClick="jamoscript:return confirm('Do you really want to do that?');">Delete all</a>
I can display the page containing it and click the link to get the confirmation dialog box exactly the same as I do when I change " jamoscript
" to " javascript
". 我可以显示包含它的页面,然后单击链接以获得与我将“
jamoscript
”更改为“ javascript
”时完全相同的确认对话框。 No diagnostics are displayed in the Firebug console, either when the page is loaded or when the link is clicked. 在加载页面或单击链接时,Firebug控制台中不会显示任何诊断信息。 What the hey?
嘿嘿? Googling for jamoscript doesn't turn up anything interesting.
谷歌搜索jamoscript并没有发现任何有趣的东西。
Can anybody explain this behavior? 任何人都可以解释这种行为吗?
The string value of an "onclick" attribute is taken to be simple JavaScript code. “onclick”属性的字符串值被视为简单的JavaScript代码。 JavaScript includes provisions for labeled statements , so that code is a
return
statement with the label "jamoscript". JavaScript包含标记语句的规定,因此代码是带有标签“jamoscript”的
return
语句。 In other words, this: 换句话说,这个:
jamoscript: return confirm("Do you really want to hurt me?");
is perfectly legal JavaScript. 是完全合法的JavaScript。 Labels aren't used much, so they're unfamiliar.
标签使用不多,所以他们不熟悉。
The only context in which the "javascript:" prefix matters is when a URL is expected, as is the case with the "href" attribute of <a>
tags. “javascript:”前缀很重要的唯一上下文是当需要URL时,就像
<a>
标签的“href”属性一样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.