文档中的Javascript执行访问点 [英] Javascript execution access points in a document

查看:62
本文介绍了文档中的Javascript执行访问点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,脚本的解释是从一个带iframe的文档开始的,该文档包含一个带"<header><script>"或可能是"<body><script>"的另一个文档.我只是真的需要确保执行在iframe文档之前的外部"文档中进行,但这似乎是随机的,对吗?

I'm wondering, where the script interpretation starts in a document with an iframe, that contains another document, with "<header><script>" or possibly "<body><script>". I just really need to ensure that the execution happens in the "outer" document before the iframe document, but it seems that it is random, is that right ?

顺便说一句,被引用的javascript的解释顺序如何?它是否取决于我引用的文档中的何处"?

BTW, what about the order of interpretation of referenced javascripts ? Does it depend on "where" in the document I reference it ?

推荐答案

我只需要确保执行在iframe文档之前的外部"文档中发生

I just really need to ensure that the execution happens in the "outer" document before the iframe document

要确保100%的确定性,您必须在外部文档的DOMReady事件中创建iframe(例如,使用jQuery的.ready()).如果直接将其嵌入文档中,则实际上无法保证脚本何时执行.

To do this with 100% certainty, you would have to create the iframe in the outer document's DOMReady event (e.g. with jQuery's .ready()). If you embed it directly into the document, there is indeed no guarantee of when the scripts will execute.

所引用的javascript的解释顺序如何?它是否取决于我引用的文档中的何处"?

what about the order of interpretation of referenced javascripts ? Does it depend on "where" in the document I reference it ?

是的,脚本块将按照它们在页面中的顺序执行.这是一个很好的解决方案:加载和执行网页的顺序?

Yes, script blocks get executed in the order they are in the page. Here is a great answer on the issue: Load and execution sequence of a web page?

这篇关于文档中的Javascript执行访问点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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