I need compatible JavaScript code for document.cre

2019-02-24 18:22发布

问题:

The JavaScript function document.createElementNS() does not work in older versions of IE (6,7,8)? Is there any compatible code for this function, like Array's compatible map function for old version IE?

回答1:

Have a look at the following google group post. There's a workaround that may help you: http://code.google.com/p/svgweb/issues/detail?id=625

Workaround (from link above):

window.onload = function() {
    function onCreateElementNsReady(func) {
        if (document.createElementNS != undefined) {
            func();
        } else {
            setTimeout(function() { onCreateElementNsReady(func); }, 100);
        }
    }

    onCreateElementNsReady(function() {
        var svg = document.createElementNS(svgns, 'svg');
        // ...
    });
};