代码之家  ›  专栏  ›  技术社区  ›  Raul Agrait

在Google Chrome中将XML加载到文档对象中

  •  1
  • Raul Agrait  · 技术社区  · 16 年前

    // 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 回复  |  直到 16 年前
        1
  •  2
  •   jonchang    16 年前

    Document.load() WebKit中尚不支持。考虑使用XMLHtpRestQuest.

    参考: chromium