javascript “交互式”与 ondomcontentloaded 的 document.readystate?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3665561/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 01:52:15  来源:igfitidea点击:

document.readystate of "interactive" vs. ondomcontentloaded?

javascriptdomonreadystatechange

提问by Yansky

Could anyone tell me the difference between the "interactive" state of document.readyState and "DOMContentLoaded"?

谁能告诉我 document.readyState 的“交互式”状态和“DOMContentLoaded”之间的区别?

I couldn't find a lot of info on the "interactive" state and what specifically is available to be used in the page.

我找不到很多关于“交互式”状态的信息,以及可以在页面中使用的具体内容。

This pagesays:

这个页面说:

interactive - Has loaded enough and the user can interact with it

交互式 - 已加载足够并且用户可以与之交互

Which seems a helluva lot like the DOMContentLoaded event.

这看起来很像 DOMContentLoaded 事件。

I wrote a quick test page herewhich seems to suggest that the interactive readystate seems to be available before the DOMContentLoaded event.

在这里写了一个快速测试页面,它似乎表明交互式就绪状态似乎在 DOMContentLoaded 事件之前可用。

So could someone clarify or give me some info on whats available to be manipulated on the page in the interactive state and whether it is the same as DOMContentLoaded and if so, why is it available before DOMContentLoaded?

那么有人可以澄清或给我一些关于在交互状态下可以在页面上操作的内容以及它是否与 DOMContentLoaded 相同的信息,如果是,为什么它在 DOMContentLoaded 之前可用?

:)

:)

Cheers, Yansky.

干杯,扬斯基。

Edit: forgot to add, you need to be running FF4b to be able to use/see the new readystate feature.

编辑:忘记添加了,您需要运行 FF4b 才能使用/查看新的就绪状态功能。

回答by Yaniv Shemesh

Once the user agent stops parsing the document, the user agent must run the following steps:

一旦用户代理停止解析文档,用户代理必须运行以下步骤:

  1. Set the current document readiness to "interactive" and the insertion point to undefined.

  2. Pop all the nodes off the stack of open elements.

  3. If the list of scripts that will execute when the document has finished parsing is not empty, run these substeps:

    a. Spin the event loop until the first script in the list of scripts that will execute when the document has finished parsing has its "ready to be parser-executed" flag set and the parser's Document has no style sheet that is blocking scripts.

    b. Execute the first script in the list of scripts that will execute when the document has finished parsing.

    c. Remove the first script element from the list of scripts that will execute when the document has finished parsing (i.e. shift out the first entry in the list).

    d. If the list of scripts that will execute when the document has finished parsing is still not empty, repeat these substeps again from substep a.

  4. Queue a task to fire a simple event that bubbles named DOMContentLoadedat the Document. . . . https://www.w3.org/TR/html5/syntax.html#the-end

  1. 将当前文档准备就绪设置为“交互”并将插入点设置为未定义。

  2. 从开放元素的堆栈中弹出所有节点。

  3. 如果文档完成解析后将执行的脚本列表不为空,请运行以下子步骤:

    一个。旋转事件循环,直到在文档完成解析时将执行的脚本列表中的第一个脚本设置了“准备被解析器执行”标志并且解析器的文档没有阻止脚本的样式表。

    。执行将在文档解析完成后执行的脚本列表中的第一个脚本。

    。从将在文档完成解析时执行的脚本列表中删除第一个脚本元素(即移出列表中的第一个条目)。

    d。如果文档完成解析后将执行的脚本列表仍然不为空,请从子步骤a再次重复这些子步骤。

  4. 将任务排队以触发一个简单的事件,该事件在文档中冒泡,名为DOMContentLoaded。. . . https://www.w3.org/TR/html5/syntax.html#the-end

回答by Yansky

Just to answer my own question here, it seems that the DOMContentLoadedevent equates to the document.interactivereadystate.

只是在这里回答我自己的问题,似乎该DOMContentLoaded事件等同于document.interactive就绪状态。