[英]Does tree mirror js and mutation summary supports iframe?
我一直在使用一個名為tree-mirror.js的開源庫,它使用mutation-summary.js來進行DOM鏡像。
一切都很好但是iframe。 當主文檔包含iframe時,這些庫不會捕獲iframe對iframe文檔的更改。 我可以通過閱讀tree-mirror.js的代碼來弄清楚它是將變異觀察者綁定到主文檔但是不明白它是否也可以自動處理iframe文檔。
我不確定圖書館是否支持這項工作,或者我錯過了什么。 有沒有人使用這些庫並遇到過這個問題? 請幫助。
編輯:感謝wOxxOm在前一個答案中指出了錯誤的結論。
簡而言之,MutationObserver API似乎不支持觀察iframe內部的更改。 請考慮以下示例:
var m = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
console.log(mutation)
});
});
// We observe child list and subtree changes
m.observe(document.body, {childList: true, subtree: true});
// Let's create an iframe
var iframe = document.createElement("iframe");
// A mutation record will be logged here
document.body.appendChild(iframe);
// However this will NOT log a mutation record
iframe.contentDocument.body.appendChild(document.createElement("div"));
所以我擔心你在這里運氣不好。 就像上面的評論中所說的那樣,你必須在每個iframe中初始化一個新的變異觀察者,以便能夠觀察他們的DOM變化。 沒有提到的庫支持這一點,因為它們主要是本機MutationObserver API的包裝器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.