我无法使用以下功能将XML文件加载到Google Chrome中的JavaScript文档中:
// load XML document based on whether the browser is IE or other browsers
function loadXMLDocument(url)
{
var doc;
if (window.ActiveXObject) // IE
{
doc = new ActiveXObject("Msxml2.DOMDocument.6.0");
doc.async = false;
doc.load(url);
alert('document loaded in IE');
}
else if (document.implementation && document.implementation.createDocument)
{
doc = document.implementation.createDocument("", "", null);
// this line seems to cause an error in Chrome
doc.load(url);
doc.onload = function()
{
alert('document loaded in other browsers except Chrome');
}
}
}
此代码在IE6 / 7,FF2 / 3.x中正常工作,但在Chrome中无效。