开发者

Can't read an XML and/or XSLT in Google Chrome

I'm trying to load some xml and xslt stuff into this following html file:

<html>
    <head>
    <script&g开发者_JAVA百科t;
    function loadXMLDoc(dname)
    {
    if (window.XMLHttpRequest)
      {
      xhttp=new XMLHttpRequest();
      }
    else
      {
      xhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xhttp.open("GET",dname,false);
    xhttp.send("");
    return xhttp.responseXML;
    }

    function displayResult()
    {
    xml=loadXMLDoc("FooBar.xml");
    xsl=loadXMLDoc("FooBar.xsl");
    // code for IE
    if (window.ActiveXObject)
      {
      ex=xml.transformNode(xsl);
      document.getElementById("FooBar").innerHTML=ex;
      }
    // code for Mozilla, Firefox, Opera, etc.
    else if (document.implementation && document.implementation.createDocument)
      {
      xsltProcessor=new XSLTProcessor();
      xsltProcessor.importStylesheet(xsl);
      resultDocument = xsltProcessor.transformToFragment(xml,document);
      document.getElementById("FooBar").appendChild(resultDocument);
      }
    }
    </script>
    </head>
    <body onload="displayResult()">
    <div id="FooBar" />
    </body>
</html>

The problem is that this code works perfectly in Apple Safari with no warnings or errors. But on Chrome, it says that XMLHttpRequest cannot load file:///C:/Path/To/fooBar.xml. Cross origin requests are only supported for HTTP.

And another problem is that I won't deploy de xml, xslt and html on any server.

Anyone can help?

Thank you.


Yes. It looks like an issue with Chrome.

http://code.google.com/p/chromium/issues/detail?id=58151 submitted on 5 October.


It's apparently a security feature of Chrome, the link provided by danny.lesnik gives detail on how to bypass.

"Try starting Google Chrome from the command line with the argument --allow-file-access OR --allow-file-access-from-files"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜