zephyrer / svgweb

Automatically exported from code.google.com/p/svgweb
Other
0 stars 0 forks source link

document.createElementNS in IE sometimes is not ready right away, gives "TypeError: Object doesn't support this property or method" #625

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I've seen a problem in IE8 (in IE8 and IE7 rendering mode) where sometimes the 
"document.createElementNS()" call fill fail.  The error is "TypeError: Object 
doesn't support this property or method".  The problem is that at first "typeof 
document.createElementNS" returns "unknown".  A little bit later (50-100ms?), 
document.createElementNS becomes valid.

So document.createElementNS() cannot be used reliably on IE until it is ready.  
This happens sometimes - if I reload the page a few times it'll happen maybe 1 
out of 4 tries.  Force-reloading (control+f5) seems to cause/fix it, randomly.

    window.onload = function() {
        // On IE, this line sometimes fails:
        var svg = document.createElementNS(svgns, 'svg');
    }

Firefox/Safari do not have this problem with native rendering.  They may with 
flash redering, I haven't checked.

I use this to work around the problem:

    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');
            // ...
        });
    )

This works consistently in IE (and other browsers).

NOTE: This is not related to DOM-readiness, as demonstrated above.

What version of the product are you using? On what operating system,
browser, and version of Flash?

This is XP SP3, IE8 (both in IE7 and IE8 rendering mode), Flash 10.2.153.1.  
Svgweb 2011-02-03 Lurker Above.

Original issue reported on code.google.com by rocketmonkeys on 31 Aug 2011 at 8:04