[英]How can I stop a Javascript from being interpreted after a certain point?
The first few lines of my script look like: 我的脚本的前几行看起来像:
if (window.location.hash) {
window.location = window.location.hash.substring(1);
}
I'd like to have the entire script "skipped" if this statement returns true. 如果此语句返回true,我希望“跳过”整个脚本。 Is there any way to do this other than putting my entire script in a giant if statement?
有没有办法做到这一点,除了把我的整个脚本放在一个巨大的if语句中?
Just return. 回来吧。
if (window.location.hash) {
window.location = window.location.hash.substring(1);
return;
}
Note that the script will still be parsed until the end, so it has to be valid JavaScript all the way through. 请注意,脚本仍将被解析直到结束,因此它必须始终是有效的JavaScript。 But I think you meant "interpreted" in the title.
但我认为你的意思是“解释”在标题中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.