views:

586

answers:

1

I am unable to load an XML file into a JavaScript Document in Google Chrome with the following function:

// 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');
     }  
    }
}

This code works fine in IE6/7, FF2/3.x, but not in Chrome.

+2  A: 

Document.load() is not yet supported in WebKit. Consider using an XmlHttpRequest.

Reference: chromium

jonchang
+1. There is a DOMParser you can have from WebKit and Mozilla, but when you're fetching a resource the simple, straightforward thing to do should be a plain old XMLHttpRequest.
bobince