PDA

View Full Version : "No such interface supported" on appendChild()


chrisbeach
06-10-2005, 04:28 PM
I've got a chunk of javascript that's giving me grief on IE though it works on Firefox (so what's new eh...?). The error I get from IE is "No such interface supported", the offending code (with the error line in bold) is:


var elToUpdate = document.getElementById(id);
var currentChildren = elToUpdate.childNodes;
while (currentChildren.length > 0)
{
elToUpdate.removeChild(currentChildren[0]);
}

var newChildren = changes[i].getElementsByTagName("content")[0].childNodes;

while (newChildren.length > 0)
{
elToUpdate.appendChild(newChildren[0]);
}


The aim is obviously to replace the current contents of the div with the supplied elements.

Two things to note:
1. the element being updated in this case is a div.
2. the newChildren var is an XML DOM from an XMLHttpRequest response.

I haven't found anyone else complaining about this, which usually means I'm doing something blindingly stupid. Feel free to tell me so, I'd really appreciate any help! :o

Kor
06-10-2005, 04:40 PM
IE and Moz count in different ways the childNodes in case there is a possible textNode (a gap) as a childNode. Maybe you should use childNodes[index].nodeType to check which child is an element and which is a real(or possible) textNode

chrisbeach
06-13-2005, 10:27 AM
Thanks for your reply Kor - much appreciated! However...I've tried modifying my code so that it only uses true elements, I've modified the generated HTML so that the fragment being added starts with a couple of element nodes (spans) and I'm still getting the same error. Updated code is:

var index = 0;
while (index < newChildren.length)
{
if (newChildren[index].nodeType == Node.ELEMENT_NODE)
{
elToUpdate.appendChild(newChildren[index]);
}
else
{
debug("skipping child: " + index + "/" + newChildren[index].nodeName);
index++
}
}

Putting some trace on this tells me that it fails (with the same error) trying to append the first <span> element when 'newChildren' is (in HTML):

<span>Search History </span><span class="history-steps">(3 search steps)</span>

Any thoughts?

Kor
06-13-2005, 10:33 AM
have u tried:

if (newChildren[index].nodeType ==1)// if child is a taged element

?

chrisbeach
06-13-2005, 10:41 AM
Yes - Node.ELEMENT_NODE is 1.

chrisbeach
06-15-2005, 01:44 PM
Just to close off this thread, I've given up trying to get this working with appendChild and gone over to the dark side of innerHTML instead... :(

donius
08-08-2005, 03:38 PM
I have been running into some issues that were a lot like this => I couldn't append a node to another node that i had created, were you by any chance trying to do this cross-window? I looked around a bunch and it seems that IE cannot handle cross-window DOM node manipulation. :eek: Boo that. :mad: So, ((seeing that this node is "officially" closed down)) a word to the wary: find another way to cross-manipulate popups and other windows if you need to use IE.

Kor
08-08-2005, 04:27 PM
it can be done cross-window, just that you must specify the window as base root reference:

Something like that should work, I guess;

var myObj = windowobject.document.createElement(tag);
windowobject.document.root_reference.appendChild(myObj);