我正在尝试修复和问题我的代码。我最初使用 DOMNodeRemoved 和 DOMNodeInserted 来关注我正在处理的页面中的元素。它们运行良好,但在 IE 中不起作用。所以我开始尝试使用 MutationObserver。
这是我在 onPageInit 上调用的代码(回调写入控制台,但我禁用了它,因为 IE 不再支持控制台):
var callback = function(allmutations){
allmutations.map( function(mr){
var mt = 'Mutation type: ' + mr.type; // log the type of mutation
mt += 'Mutation target: ' + mr.target; // log the node affected.
//console.log( mt );
})
}
mo = new MutationObserver(callback),
options = {
// required, and observes additions or deletion of child nodes.
'childList': true,
// observes the addition or deletion of "grandchild" nodes.
'subtree': true
}
alert('its alive');
mo.observe(document.body, options);
它在 chrome 中运行良好,但由于某种原因在 IE 中表现平平。我在加载页面时收到一个消息框,上面写着:
An unexpected error occurred in a script running on this page.
onPageInit(pageInit)
scriptname
JS_EXCEPTION
TypeError 'MutationObserver' is undefined
难道我做错了什么?附加信息:页面是一个网络套件页面,运行 jQuery 1.7.2(如果重要)