javascript - 将 XML 加载到 Google Chrome 中的 Document 对象

标签 javascript xml cross-browser google-chrome

我无法使用以下函数将 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 中运行不正常。

最佳答案

WebKit 尚不支持

Document.load()。考虑使用 XmlHttpRequest。

引用:chromium

关于javascript - 将 XML 加载到 Google Chrome 中的 Document 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1886252/

相关文章:

YouTube iframe 的 JavaScript 播放/暂停按钮

javascript - $state.go 没有按照 promise 工作

html - 文本溢出 : ellipsis doesn't work after line break in Internet Explorer

javascript - 带 class 的 div 的 jquery 选择器

javascript - 使整个 div(包括文本)可点击

xml - 我自己的 SOAP 代码?

java - 1 个 View android 布局上的 2 个属性

xml - XSL : output of "nested" structures

Firefox Div 对齐不起作用;适用于 Chrome、IE 和 Safari

internet-explorer - IE9酸3测试?