I need compatible JavaScript code for document.cre

2019-02-24 18:08发布

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条回答
劳资没心,怎么记你
2楼-- · 2019-02-24 18:36

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');
        // ...
    });
};
查看更多
登录 后发表回答