ReMaX
04-24-2008, 03:13 AM
Heyho,
I have a problem: I made a window handler class. It is great and I am very proud of it :cool: but there is the problem that it now runs the document.write function although I'd like to run it in a spontaneous call in the context and not every time at the end of the document. I tried to use that loadXMLString function of the w3c but it doesn't work.
Here's a short example:
function VirtualWindows() {
this.putContent = function(windowcontent) {
var content = this.loadXMLString(windowcontent);
var mainbody = document.getElementsByTagName("body")[0];
mainbody.appendChild(content.documentElement);
};
this.loadXMLString = function(txt) {
try { //Internet Explorer
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = "false";
xmlDoc.loadXML(txt);
return(xmlDoc);
}
catch(e) {
try { //Firefox, Mozilla, Opera, etc.
parser = new DOMParser();
xmlDoc = parser.parseFromString(txt,"text/xml");
return(xmlDoc);
}
catch(e) { alert(e.message); }
}
return(null);
};
}
call:
var windowmanager = new VirtualWindows();
windowmanager.putContent('<div class="testmessage">hey, I am a test. What do you are? <div><span>I am a child element that only has one parent</span></div><div></div></div>');
Why doesn't this work? If I try alert(content.documentElement.nodeName); at the end of the putContent() function "div" appears but I cannot get the class, there is no possibility to implement it in the document and nothing else works.
Please, help!!! :confused:
greetings
Max
I have a problem: I made a window handler class. It is great and I am very proud of it :cool: but there is the problem that it now runs the document.write function although I'd like to run it in a spontaneous call in the context and not every time at the end of the document. I tried to use that loadXMLString function of the w3c but it doesn't work.
Here's a short example:
function VirtualWindows() {
this.putContent = function(windowcontent) {
var content = this.loadXMLString(windowcontent);
var mainbody = document.getElementsByTagName("body")[0];
mainbody.appendChild(content.documentElement);
};
this.loadXMLString = function(txt) {
try { //Internet Explorer
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = "false";
xmlDoc.loadXML(txt);
return(xmlDoc);
}
catch(e) {
try { //Firefox, Mozilla, Opera, etc.
parser = new DOMParser();
xmlDoc = parser.parseFromString(txt,"text/xml");
return(xmlDoc);
}
catch(e) { alert(e.message); }
}
return(null);
};
}
call:
var windowmanager = new VirtualWindows();
windowmanager.putContent('<div class="testmessage">hey, I am a test. What do you are? <div><span>I am a child element that only has one parent</span></div><div></div></div>');
Why doesn't this work? If I try alert(content.documentElement.nodeName); at the end of the putContent() function "div" appears but I cannot get the class, there is no possibility to implement it in the document and nothing else works.
Please, help!!! :confused:
greetings
Max