PDA

View Full Version : I can't figure out whats wrong...



???
08-05-2007, 05:12 PM
These 2 lines are getting me:


frame.contentDocument.getElementsByTagName ("html") [0].innerHTML = theXML;
alert (frame.contentDocument.getElementsByTagName ("html") [0].innerHTML);

It doesn't appear on screen, but then the alert says what I want it to say.
The entire code is:


<html>
<head>
<script type="text/javascript">
window.onload = function () {
for (var i = 0; i < document.getElementsByTagName ("xml").length; i = i + 1) {
var tag = document.getElementsByTagName ("xml") [i];
var theXML = "<?" + tag.getAttribute ("doctype") + "?>" + tag.innerHTML;
tag.innerHTML = "";
var frame = document.createElement ("iframe");
frame.setAttribute ("src","about:blank");
tag.appendChild (frame);
frame.contentDocument.getElementsByTagName ("html") [0].innerHTML = theXML;
alert (frame.contentDocument.getElementsByTagName ("html") [0].innerHTML);
}
}
</script>
</head>
<body>
<xml doctype='version="1.0" encoding="ISO-8859-1"'>
<root>
hahaha
</root>
</xml>
</body>
</html>

I did it before with it writing about:blank, but right now I can't figure out whats wrong.

???
08-06-2007, 12:14 AM
Now I'm more puzzled. It works when I click if I put it in an onclick event, it just doesn't seem to want to work immediately, I even tried putting it in a different function. Might this be a bug?

Twey
08-06-2007, 12:32 AM
frame.setAttribute ("src","about:blank"); -- perhaps it hasn't finished loading about:blank? This doesn't block, you know. Make use of onload.