javascript< script>标记 - 在src下载之前执行代码 [英] javascript <script> tag - code execution before src download

查看:248
本文介绍了javascript< script>标记 - 在src下载之前执行代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这段代码中,

 < script src =需要很长时间才能下载type =text / javascript> ; 
alert('hi');
< / script>

让我们假设脚本需要很长时间下载。脚本下载完成之前,有没有机会提醒hi可以触发?如果是,哪些浏览器可以这样做?
请注意,我已将alert('hi')置于同一个标记中。



谢谢

解决方案

alert('hi')永远不会触发,因为脚本标签支持嵌入代码 外部文件代码。 阅读 http://www.w3.org/TR/html4/interact /scripts.html#h-18.2.1


脚本可以在SCRIPT元素的内容中定义在外部文件中。如果未设置src属性,则用户代理必须将该元素的内容解释为脚本。 如果src具有URI值,则用户代理必须忽略元素的内容并通过URI检索脚本。



In this snippet

<script src="takes very long to download" type="text/javascript">
  alert('hi');
</script>

Lets assume that script takes a very long time to download. Is there a chance that alert "hi" could fire before the download of script has completed? If yes, which browsers could do so? Note that I have placed "alert('hi')" inside the same tag on purpose.

Thanks

解决方案

alert('hi') would never fire, as the script tag supports either inline code or external file code..

Read the specs at http://www.w3.org/TR/html4/interact/scripts.html#h-18.2.1

The script may be defined within the contents of the SCRIPT element or in an external file. If the src attribute is not set, user agents must interpret the contents of the element as the script. If the src has a URI value, user agents must ignore the element's contents and retrieve the script via the URI.

这篇关于javascript&lt; script&gt;标记 - 在src下载之前执行代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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