[英]MutationObserver hangs in IE11
I am using MutationObserver to check when some nodes are removed and replaced by other new nodes to an element. 我正在使用MutationObserver检查何时删除了某些节点,并用元素的其他新节点替换了这些节点。
The following code works totally fine in Chrome, but on IE11 it just hangs. 以下代码在Chrome中可以正常运行,但是在IE11上它只是挂起。
If I change the addedNodes check with removedNodes, it works on IE11. 如果我更改了removeedNodes的addingNodes检查,则它可以在IE11上运行。 I just don't understand why it hangs when I check for new nodes being added.
我只是不明白为什么在检查要添加的新节点时它会挂起。
Any idea? 任何想法? I can't find any resources for this issue.
我找不到此问题的任何资源。
var nodeToObserve = document.querySelector('#targetNode'); var callback = function(mutations, observer) { for (var index = 0; index < mutations.length; index) { var mutation = mutations[index]; if (mutation.type === 'childList' && mutation.addedNodes.length > 0) { console.log(mutation); break; } } observer.disconnect(); } const observer = new MutationObserver(callback); observer.observe(nodeToObserve, { childList: true, // target node's children subtree: true // target node's descendants });
html, body { height: 100%; } #targetNode { border: 1px solid black; height: 100%; } .childNode { //height: 20px; background-color: blue; margin: 10px; padding: 10px; } .grandChildNode { height: 20px; background-color: red; margin: 10px; }
<div id="targetNode"> </div>
You aren't incrementing the index
in your for
loop. 您不会在
for
循环中增加index
。 Probably the results appear in a different order depending on the browser so the if
statement will be triggered on some browsers but not others. 结果可能会以不同的顺序出现,具体取决于浏览器,因此
if
语句将在某些浏览器上触发,但在其他浏览器上不会触发。 Thus, the system will hang when the if
statement isn't executed b/c of the infinite loop. 因此,
if
不执行无限循环b / c的if
语句,系统将挂起。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.