JavaScript error "'script.parentNode' is null or not an object" on IE when running multiple instances of fluid (swfobject.js)
Description
The swfobject.js dependency, included with Fluid Infusion, causes A JavaScript error on IE browsers when you run more than 1 copy of fluid on a page. (Note: this is something we do commonly in uPortal – each portlet loads & uses its own copy.)
The error is caused when JS attempts to call 'script.parentNode.removeChild(script)' on the same element more than once.
Will fire an event as soon as the DOM of a page is loaded (supported by Gecko based browsers - like Firefox -, IE, Opera9+, Safari) */ var onDomLoad = function() { if (!ua.w3cdom) { return; } addDomLoadEvent(main); if (ua.ie && ua.win) { try { // Avoid a possible Operation Aborted error doc.write("<scr" + "ipt id=__ie_ondomload defer=true src=//:></scr" + "ipt>"); // String is split into pieces to avoid Norton AV to add code that can cause errors script = getElementById("__ie_ondomload"); if (script) { addListener(script, "onreadystatechange", checkReadyState); } } catch(e) {} } if (ua.webkit && typeof doc.readyState != UNDEF) { timer = setInterval(function() { if (/loaded|complete/.test(doc.readyState)) { callDomLoadFunctions(); }}, 10); } if (typeof doc.addEventListener != UNDEF) { doc.addEventListener("DOMContentLoaded", callDomLoadFunctions, null); } addLoadEvent(callDomLoadFunctions); }();
function checkReadyState() {
if (script.readyState == "complete") { script.parentNode.removeChild(script); callDomLoadFunctions(); } } *****
Environment
IE browser, all versions (afaik)
Attachments
1
Activity
Show:
Mike Lam September 8, 2010 at 5:42 PM
Committed and available to trunk, 1.1.3, 1.2.1, and 1.3.
Harris Wong August 24, 2010 at 6:25 PM
Replaced SWFObject v2.1 to SWFObject v2.2. Changed the version number on the readme file and the swfobject-LICENSE file.
The swfobject.js dependency, included with Fluid Infusion, causes A JavaScript error on IE browsers when you run more than 1 copy of fluid on a page. (Note: this is something we do commonly in uPortal – each portlet loads & uses its own copy.)
The error is caused when JS attempts to call 'script.parentNode.removeChild(script)' on the same element more than once.
Eyeballing the code, it looks as though this issue is fixed in swfobject 2.2: http://code.google.com/p/swfobject/downloads/detail?name=swfobject_2_2.zip
Would it be possible to bump the embedded version of swfobject to 2.2?
OFFENDING CODE *****
/* Cross-browser onDomLoad
Based on Dean Edwards' solution: http://dean.edwards.name/weblog/2006/06/again/
Will fire an event as soon as the DOM of a page is loaded (supported by Gecko based browsers - like Firefox -, IE, Opera9+, Safari)
*/
var onDomLoad = function() {
if (!ua.w3cdom) {
return;
}
addDomLoadEvent(main);
if (ua.ie && ua.win) {
try { // Avoid a possible Operation Aborted error
doc.write("<scr" + "ipt id=__ie_ondomload defer=true src=//:></scr" + "ipt>"); // String is split into pieces to avoid Norton AV to add code that can cause errors
script = getElementById("__ie_ondomload");
if (script) {
addListener(script, "onreadystatechange", checkReadyState);
}
}
catch(e) {}
}
if (ua.webkit && typeof doc.readyState != UNDEF) {
timer = setInterval(function() { if (/loaded|complete/.test(doc.readyState)) { callDomLoadFunctions(); }}, 10);
}
if (typeof doc.addEventListener != UNDEF) {
doc.addEventListener("DOMContentLoaded", callDomLoadFunctions, null);
}
addLoadEvent(callDomLoadFunctions);
}();
function checkReadyState() {
if (script.readyState == "complete") {
script.parentNode.removeChild(script);
callDomLoadFunctions();
}
}
*****