2014-03-04 71 views
0

所以SDK有這個函數檢查窗口是否加載,代碼如下。檢查window dom是否被解析

我的問題是如果一個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; 

,但確實的readyState進入互動被解析innerHTML的時候?我想知道什麼時候頁面完全呈現。

回答

1

動態HTML更改不影響document.readyState property,它是單向街道。該值是"loading"在文檔被解析,"interactive"一旦解析完,圖像等東西只需要加載(DOMContentLoaded觸發的事件)和"complete"一旦一切都做(load觸發的事件)。之後它不再改變。

+0

啊,你認爲dom分析器需要多少時間才能渲染像appendChild和innerHTML更新這樣的東西?沒有繪製完整的事件? – Noitidart

+1

@Noitidart:渲染髮生異步,只有DOM變化是同步的。 'innerHTML'可能需要一段時間,這取決於HTML代碼的複雜程度。另一方面'appendChild'非常快 - 這裏不涉及解析。有['MozAfterPaint'事件](https://developer.mozilla.org/en-US/docs/Web/Reference/Events/MozAfterPaint),但你不知道哪一個是「最終」的繪畫事件。 –

+0

Ahhh非常感謝那個MozAfterPaint,我知道我記得那樣的東西,但找不到它。好的,謝謝Wlad! – Noitidart