引言

  通过JS加载XML文件,跨多种浏览器兼容。

  在Chrome中,没有load方法,需要特殊处理!

解决方案

  部分代码

try //Internet Explorer
{
 xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
 xmlDoc.async=false;
 xmlDoc.load(file);
}
catch(e)
{
 try //Firefox, Mozilla, Opera, etc.
 {
  xmlDoc=document.implementation.createDocument("","",null);
  xmlDoc.async=false;
  xmlDoc.load(file);
 }
 catch(e)
 {
  try //Google Chrome
  {
   var xmlhttp = new window.XMLHttpRequest();
   xmlhttp.open("GET",file,false);
   xmlhttp.send(null);
   xmlDoc = xmlhttp.responseXML.documentElement;
  }
  catch(e)
  {
   error=e.message;
  }
 }
}

   完整代码

    function parseXML(file){
        var xmlDoc;
        try //Internet Explorer
        {
         xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
         xmlDoc.async=false;
         xmlDoc.load(file);
        }
        catch(e)
        {
         try //Firefox, Mozilla, Opera, etc.
         {
          xmlDoc=document.implementation.createDocument("","",null);
          xmlDoc.async=false;
          xmlDoc.load(file);
         }
         catch(e)
         {
          try //Google Chrome
          {
           var xmlhttp = new window.XMLHttpRequest();
           xmlhttp.open("GET",file,false);
           xmlhttp.send(null);
           xmlDoc = xmlhttp.responseXML.documentElement;
          }
          catch(e)
          {
           error=e.message;
          }
         }
        }
        return xmlDoc;
    }

最新文章

  1. 比较牛X的互联网公司都有哪些作死的行为
  2. [jquery]折叠指定条件的表格
  3. vc++ 判断文件或是文件夹是否存在,比较好的做法
  4. YHLMR007 服装PDA验货差异报表
  5. 用msbuild跑xunit单元测试
  6. Leetcode: Lexicographical Numbers
  7. 在js自定义函数中使用$(event.target)代替$(this)
  8. UVALive 4255 Guess
  9. Unicode和字符集小结
  10. Hadoop:Task process exit with nonzero status of 1 异常
  11. http keepalive and tcpkeepalive
  12. 《Getting Started with WebRTC》第一章 WebRTC介绍
  13. .NET/ASP.NETMVC Model元数据、HtmlHelper、自定义模板、模板的装饰者模式(一)
  14. CRS-2800 CRS-4000
  15. Linux下安装oracle jdk
  16. 推荐系统 LFM 算法的简单理解,感觉比大部分网上抄来抄去的文章好理解
  17. Java进阶篇设计模式之十一 ---- 策略模式和模板方法模式
  18. SSRS奇怪报错Could not update a list of fields for the quer.
  19. 作业20171026 alpha-2及alpha发布成绩
  20. PAT L2-022 重排链表

热门文章

  1. GYM 100741A Queries
  2. laravel5.2数据库基本操作
  3. chorme dev tools的小技巧
  4. vue-router 基本知识点
  5. C#文件读写参考
  6. c# KeyDown KeyPress 函数中event 的 Handled属性
  7. IDEA thymeleaf ${xxx.xxx}表达式报错,红色波浪线
  8. 基于 React-draft-wysiwyg 实现的 react 富文本编辑器组件 开箱即用
  9. sybase修改默认字符集为cp936
  10. Tcp实现省略编码