在IE浏览器下,xmlDom对象一般这样被定义:
var xmlDom= new ActiveXObject("Microsoft.XMLDOM");
为了兼容Firefox,需要修改为:
if (window.ActiveXObject){
var xmlDom=new ActiveXObject("Microsoft.XMLDOM");
}
else{
if (document.implementation&& document.implementation.createDocument){
var xmlDom= document.implementation.createDocument("","",null);
}
}
var oParser=new DOMParser();
xmlDom=oParser.parseFromString(xmlStr,"text/xml");
try{
if (window.ActiveXObject){
xmlDoc= new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
isLoaded = xmlDoc.load(aXMLFileName);
}
else if
(document.implementation&& document.implementation.createDocument){
try{
xmlDoc = document.implementation.createDocument('', '', null);
xmlDoc.async = false;
xmlDoc.load(aXMLFileName);
} catch(e){
var xmlhttp = new window.XMLHttpRequest();
xmlhttp.open("GET",aXMLFileName,false);
xmlhttp.send(null);
xmlDoc = xmlhttp.responseXML;
}
}
else{
alert("load data error");
}
}
catch(e){
alert(e.message);
}