...

View Full Version : Error in IE when Appending Nested Objects



rolandog
03-31-2006, 04:14 PM
Hello everyone, I need some help on a small issue... I'm writing examples for placing standards-compliant java applets in XHTML or HTML documents. And I'm also testing with Javascript.

At some point, I created two 'object' elements, each with their 'param' children.

I'm using the 'nested objects' approach to showing/hiding an object from Internet Explorer (http://rolandog.com/freemind/freemindbrowser.html). But when I try with Javascript, I get an error when I'm appending an object to another object in Internet Explorer.

I wrote a page detailing the error in Internet Explorer (http://rolandog.com/freemind/errorinie.html).

I had created two objects (each with their sets of 'params'), and I'm appending one to the other, since I'm dynamically replicating a method for showing an applet in Internet Explorer and other browsers. (The static code seems to be valid XHTML and HTML).

I'll paste the long code here so that you guys understand what I'm talking about. Firefox and other browsers will ignore the nested object, and Internet Explorer will not see the parent object with the adapted conditional CSS hack.

Here is the code through which I'm creating the two objects:



function testfmC() {
var pC0 = document.createElement("param");
var pC1 = document.createElement("param");
var pC2 = document.createElement("param");
var pC3 = document.createElement("param");
var pC4 = document.createElement("param");
pC0.setAttribute("name","scriptable");
pC0.setAttribute("value","false");
pC1.setAttribute("name","modes");
pC1.setAttribute("value","freemind.modes.browsemode.BrowseMode");
pC2.setAttribute("name","browsemode_initial_map");
pC2.setAttribute("value","http://rolandog.com/freemind/Polietileno.mm");
pC3.setAttribute("name","initial_mode");
pC3.setAttribute("value","Browse");
pC4.setAttribute("name","selection_method");
pC4.setAttribute("value","selection_method_direct");
var oC = document.createElement("object");
oC.setAttribute("classid","java:freemind.main.FreeMindApplet.class");
oC.setAttribute("type","application/x-java-applet");
oC.setAttribute("archive","http://rolandog.com/freemind/freemindbrowser.jar");
oC.setAttribute("width","600");
oC.setAttribute("height","400");
oC.appendChild(pC0);
oC.appendChild(pC1);
oC.appendChild(pC2);
oC.appendChild(pC3);
oC.appendChild(pC4);
return oC;
}
function testfmD() {
var pD0 = document.createElement("param");
var pD1 = document.createElement("param");
var pD2 = document.createElement("param");
var pD3 = document.createElement("param");
var pD4 = document.createElement("param");
var pD5 = document.createElement("param");
var pD6 = document.createElement("param");
pD0.setAttribute("name","code");
pD0.setAttribute("value","freemind.main.FreeMindApplet");
pD1.setAttribute("name","archive");
pD1.setAttribute("value","http://rolandog.com/freemind/freemindbrowser.jar");
pD2.setAttribute("name","scriptable");
pD2.setAttribute("value","false");
pD3.setAttribute("name","modes");
pD3.setAttribute("value","freemind.modes.browsemode.BrowseMode");
pD4.setAttribute("name","browsemode_initial_map");
pD4.setAttribute("value","http://rolandog.com/freemind/Polietileno.mm");
pD5.setAttribute("name","initial_mode");
pD5.setAttribute("value","Browse");
pD6.setAttribute("name","selection_method");
pD6.setAttribute("value","selection_method_direct");
var oD = document.createElement("object");
oD.setAttribute("class","java");
oD.setAttribute("classid","clsid:8AD9C840-044E-11D1-B3E9-00805F499D93");
oD.setAttribute("codebase","http://java.sun.com/update/1.5.0/jinstall-1_5_0-windows-i586.cab");
oD.setAttribute("width","600");
oD.setAttribute("height","400");
oD.appendChild(pD0);
oD.appendChild(pD1);
oD.appendChild(pD2);
oD.appendChild(pD3);
oD.appendChild(pD4);
oD.appendChild(pD5);
oD.appendChild(pD6);
return oD;
}
var tC = testfmC();
var tD = testfmD();
tC.appendChild(tD); // the error occurs here! (line 179) in errorinie.html
document.getElementById("testfm2").appendChild(tC);


I was just curious to see if the solution was still achievable without having to resort to browser detection... if anyone has a workaround for this, please let me know.

jscheuer1
03-31-2006, 07:21 PM
For Java, have you tried creating just one <applet> element? I've had good luck with that.

rolandog
03-31-2006, 08:17 PM
Hi jscheuer1. Thanks for your response.

I haven't tried creating applet elements because they were deprecated for XHTML and HTML 4.01. Everything has to be done with the <object> element.

You can even place images with the object element, but IE (as usual) has its flaws and I think it places some scrollbars around the image.

My objective is to be as W3C (http://www.w3.org/) compliant as possible... even when writing stuff with Javascript.

If you check for validation the source code, or the generated source code... they'll both comply with the validator (http://validator.w3.org/).

jscheuer1
03-31-2006, 09:13 PM
Well in matters like that, a transitional DOCTYPE will validate. As a possible solution using a strict DOCTYPE, rather than create nested tags, perhaps create a conditional comment block for IE, just a thought. Also, I didn't see anything that looked like it could be a means test (different from browser sniffing but often has the same effect), but I didn't scrutinize your code enough to be certain. As you say IE6 has yet to support the object tag in the way other browsers do, perhaps with IE7. This keeps me thinking transitional might be the way to go as that fits the situation.

Beagle
03-31-2006, 09:50 PM
I too ended up rolling back from strict to transitional for pages with applets. Browser support for the various object tag features just wasn't solid enough. Too many problems I ran into.

rolandog
04-01-2006, 05:32 AM
Hmm, I see what you guys mean... Thanks for your advice.

I think I'll keep the strict validation... but since I'm using JS, a bit of object detection can't do much harm.

Again, thanks for your help. Have a nice weekend!

KC-Luck
04-03-2006, 04:09 PM
also, with IE there is a problem with dynamically creating an object element.

your


var oD = document.createElement("object");
oD.setAttribute("class","java");
oD.setAttribute("classid","clsid:8AD9C840-044E-11D1-B3E9-00805F499D93");


will not setup the object appropriately, and you would get an error, not allowed to "set after runtime" or whatever it is...

you should use the propietary method of IE (http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/createelement.asp) where you send more of an html string to
document.createElement("<object classid='...' type='...'/>")
or better yet, just dump all the <object><param> to an innerHTML of a temp object, then move the firstChild of that temp to where you need it in DOM.

for IE's object support is very tidious when you try to wire it up this way, and even by setting some properties/attributes in dif orders will really funk up the object, and not receive the desired results.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum