' javascript:'是什么时候前缀有效的语法? [英] When is the 'javascript:' prefix valid syntax?

查看:36
本文介绍了' javascript:'是什么时候前缀有效的语法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道您可以对< a> 标记中的URL使用javascript:伪协议.但是,我注意到Firefox和IE都将允许 javascript:'放在< script> 标记内的javascript代码之前.这是有效的语法吗?它会改变范围规则吗?

I know that you can use a javascript: pseudo protocol for URLs in an <a> tag. However, I've noticed that Firefox and IE will both allow 'javascript:' to precede javascript code within a <script> tag. Is this valid syntax? Does it change the scoping rules?

示例:我已经看过很多次了:

Examples: I've seen this many times:

<a onclick="javascript:alert('hello world!');">Hello World!</a>

但这是合法/有效的语法吗,它做了什么特殊的事情:

But is this legal/valid syntax and does it do anything special:

<script type="text/javascript">
javascript:alert('hello world!');
</script>

推荐答案

name href 属性之外(此处是协议说明符):仅创建<一个href ="https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Statements/Label" rel ="noreferrer">一个标签(例如,可能会与 continue一起使用 break ).

Outside of the href attribute (where it is a protocol specifier), name: just creates a label (such as one might use with a continue or break).

这篇关于&amp;#39; javascript:&amp;#39;是什么时候前缀有效的语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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