Search code examples
javascriptjqueryinternet-explorer-11netsuitemutation-observers

Mutation Observer is undefined


I am attempting to fix and issue with my code. I was originally using DOMNodeRemoved and DOMNodeInserted for keeping an eye on an element within a page I am working on. They worked well but did not function in IE. So I started trying to work with a MutationObserver.

Here is my Code it's called on onPageInit(the callback writes to the console but I disabled it since IE no longer supports console):

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);

It works fine in chrome, however for some reason falls flat in IE. I get a message box during load of the page that says :

An unexpected error occurred in a script running on this page.
onPageInit(pageInit)
scriptname

JS_EXCEPTION
TypeError 'MutationObserver' is undefined

Am I doing something wrong? Additional info: Page is a netsuite page, running jQuery 1.7.2 (if it matters)


Solution

  • That method was added in IE11, therefore it won't be available if the browser is running in compatibility mode for anything other than IE11.

    http://msdn.microsoft.com/en-us/library/ie/dn265034(v=vs.85).aspx