BUG: IE10 - DOMContentLoaded callback in cocos2d.js

Hey everyone,

I found a bug in cocos2d.js that causes it to not work with IE10, and might affect other people. The bug is in every cocos2d.js file:

window.addEventListener('DOMContentLoaded', function () {
        //first load engine file if specified
        var s = d.createElement('script');

        ...

        d.body.appendChild(s);
        s.c = c;
        s.id = 'cocos2d-html5';
}

Here’s what’s happening:

  • JSLoader.js is loaded as the new element’s source
  • When it gets appended to the document, the script immediately begins execution
  • When JSLoader.js tries to find the script tag with ID ‘cocos2d-html5’, it fails because the ID nor the c data has been set

If you move the appendChild call after setting the ID, everything works nicely.

I forked the repository and submitted a fix, so hopefully it gets merged into main. I posted just in case anyone else was running into the issue.

Thank you