HTML import

A

alex bazan

I've got this piece of code that imports an XML document ... it works
for both mozilla and IE.

function getXMl(url) {

if (!document.all) {
var xmlDoc = document.implementation.createDocument('','doc',null);
var xmlHTTP = new XMLHttpRequest();
xmlHTTP.overrideMimeType("text/xml");
xmlHTTP.open("GET",url, false);
xmlHTTP.send(null);
xmlDoc=xmlHTTP.responseXML;
} else {
try {
xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
} catch (e) {
xmlDoc = new ActiveXObject("Msxml.DOMDocument");
}
xmlDoc.async="false";
xmlDoc.load(url);
}
return xmlDoc;
}

With mozilla i can use the same code to import an HTML file instead of
an XML file with no problems... but the object in IE expects a valid XML
file, so it does not work (xmlDoc.xml and xmlDoc.text gives me an
empty string output)...

Which is the object that will allow me to import an HTML file in IE?

thanks in advance.
alex.
 
M

Martin Honnen

alex said:
I've got this piece of code that imports an XML document ... it works
for both mozilla and IE.

function getXMl(url) {

if (!document.all) {
var xmlDoc = document.implementation.createDocument('','doc',null);
var xmlHTTP = new XMLHttpRequest();
xmlHTTP.overrideMimeType("text/xml");
xmlHTTP.open("GET",url, false);
xmlHTTP.send(null);
xmlDoc=xmlHTTP.responseXML;
} else {
try {
xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
} catch (e) {
xmlDoc = new ActiveXObject("Msxml.DOMDocument");
}
xmlDoc.async="false";
xmlDoc.load(url);
}
return xmlDoc;
}

With mozilla i can use the same code to import an HTML file instead of
an XML file with no problems... but the object in IE expects a valid XML
file, so it does not work (xmlDoc.xml and xmlDoc.text gives me an empty
string output)...

Which is the object that will allow me to import an HTML file in IE?

You can use the download behavior with IE/Win if you want the text of an
HTML file, see
<http://www.faqts.com/knowledge_base/view.phtml/aid/1268/fid/126>

There is also
new ActiveXObject('Microsoft.XMLHTTP')
which has the same API as XMLHttpRequest thus if for Mozilla
responseText gives you what you need then you could use

var httpReqest;
if (typeof XMLHttpRequest != 'undefined') {
httpRequest = new XMLHttpRequest();
}
else if (typeof ActiveXObject != 'undefined') {
httpRequest = new ActiveXObject('Microsoft.XMLHTTP');
}
httpRequest.open('GET', url, true);
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState == 4) {
// use httpRequest.responseText here
alert(httpRequest.responseText);
}
};
httpRequest.send(null);
 
A

alex bazan

En/na Martin Honnen ha escrit:
There is also
new ActiveXObject('Microsoft.XMLHTTP')
which has the same API as XMLHttpRequest thus if for Mozilla
responseText gives you what you need then you could use

thanks this worked!!
alex.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top