1
我無法將XML文件加載到一個JavaScript文件在谷歌瀏覽器具有以下功能:加載XML到谷歌瀏覽器文檔對象
// 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中。
+1。您可以從WebKit和Mozilla獲得DOMParser,但是當您獲取資源時,簡單直接的事情應該是普通的舊XMLHttpRequest。 – bobince 2009-12-14 04:04:11