2014-03-04 4 views
0

그래서 SDK에 윈도우가로드되는지 확인하는이 함수가 있습니다. 그 코드는 아래에 있습니다.윈도우 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; 

는하지만 innerHTML을 구문 분석 될 때 대화 형으로 이동 readyState가 무엇입니까? 페이지가 완전히 렌더링 된시기를 알고 싶습니다.

답변

1

동적 HTML 변경은 document.readyState property에 영향을 미치지 않으며, 단방향 길입니다. 문서가 구문 분석되는 동안 값은 "loading"이고, 구문 분석이 완료되면 "interactive"이 처리되고 모든 것이 완료되면 이미지 (예 : DOMContentLoaded 이벤트 발생) 및 "complete"이로드되어야합니다 (load 이벤트 발생). 그 후 더 이상 변경되지 않습니다.

+0

Ah drats, 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