0

所以 SDK 有这个函数来检查窗口是否正在加载,代码如下。

我的问题是如果发生了 innerHTML 或 appendChild 或改变 html 的东西怎么办?这会带回 loadContext 吗?我想知道窗口中的 DOM 是完全解析完成还是正在进行解析,这种方法可以吗?

编辑:实际上这是查看文档是否已加载的代码:

const isInteractive = window =>
  window.document.readyState === "interactive" ||
  isDocumentLoaded(window) ||
  // XUL documents stays '"uninitialized"' until it's `readyState` becomes
  // `"complete"`.
  isXULDocumentWindow(window) && window.document.readyState === "interactive";
exports.isInteractive = isInteractive;

const isXULDocumentWindow = ({document}) =>
  document.documentElement &&
  document.documentElement.namespaceURI === XUL_NS;

/**
* Check if the given window is completely loaded.
* i.e. if its "load" event has already been fired and all possible DOM content
* is done loading (the whole DOM document, images content, ...)
* @params {nsIDOMWindow} window
*/
function isDocumentLoaded(window) {
  return window.document.readyState == "complete";
}
exports.isDocumentLoaded = isDocumentLoaded;

但是在解析 innerHTML 时,readyState 是否会进入交互状态?我想知道页面何时完全呈现。

4

1 回答 1

1

Dynamic HTML changes don't affect the document.readyState property, it is a one-way street. The value is "loading" while the document is being parsed, "interactive" once parsing is done and only things like images need to load (DOMContentLoaded event fired) and "complete" once everything is done (load event fired). It no longer changes after that.

于 2014-03-04T19:36:46.823 回答