...

View Full Version : addLoadEvent, appendChild – IE 6



VIPStephan
08-11-2008, 02:44 PM
OK, two problems in IE 6 (and in IE 6 only):

I’m using addLoadEvent (http://simonwillison.net/2004/May/26/addLoadEvent/) for my scripts and niceforms (http://www.emblematiq.com/lab/niceforms/) to enhance my form elements. As far as I’ve read addLoadEvent should add a new event without interfering with previously (or later) assigned onload events. This seems to fail in my case and while I could overcome the issue by changing niceforms’ window.onload event to an addLoadEvent function this doesn’t work in IE 6 and I have no idea why.

It does work if I change the order in which the scripts are included in my documents (i. e. if I call niceforms.js before scripts.js). However, I can’t do that because niceforms is a little buggy in that it’s not flexible enough to calculate positions when elements are removed from the DOM or hidden after niceforms has been initalized which I do on http://vipstephan.de/temp/buchfinder.htm, so I have to call scripts.js befaore niceforms.js. What’s the problem and how can I solve it?

The second thing is a minor issue but I also don’t get it. If you examine scripts.js you’ll see that I add a print button to the pages but IE 6 gives me the error: “'text' is undefined”. Why is that? I’ve defined 'text' a few lines above.

Any help is greatly appeciated.

VIPStephan
08-11-2008, 10:34 PM
OK, well, I was able to “fix” the first issue because I’m using mootools for some more effects and the DOMReady function isn’t interfering with the onload event of niceforms anymore.

However, I still don’t know why IE 6 won’t append the text I’ve defined before. Just in case you’re too lazy to look at the files here’s the simple function:


var druck = document.createElement('a');
druck.setAttribute('id','drucken');
druck.setAttribute('href',''); // IE braucht href-Attribut, um CSS :hover zu unterstützen
var text = document.createTextNode('Seite drucken');
druck.appendChild(text);
document.getElementById('kopf').appendChild(druck);
druck.onclick = function() {window.print();}


It says 'text' is undefined. :confused:

VIPStephan
08-12-2008, 08:38 PM
Hm, it’s very strange… I’ve created a simple testing file and there I could append the element(s) correctly. So then I recreated the original HTML file step by step and created a new JS file, copying the JS from the old JS file step by step as well and then it worked as if it had always been like that. It seems like IE didn’t like the JS file being called scripts.js because the new one has a different name and it works. :confused:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum