(Conversion) How to Make activexobject ("Microsoft. xmldom") object display data in a non-IE browser? Firefox)

Source: Internet
Author: User

tag: use AR strong file data for blog HTTP Io OS

如何让ActiveXObject( "Microsoft.XmlDom ")对象在非IE浏览器下显示数据?firefox(火狐) 2013-09-10 16:01 2152人阅读 评论(0) 收藏 举报

在IE浏览器下,xmlDom对象一般这样被定义:

[html] view plaincopy
  1. var xmlDom= new ActiveXObject("Microsoft.XMLDOM");  

为了兼容Firefox,需要修改为:

[html] view plaincopy
  1. if (window.ActiveXObject){  
  2.     var xmlDom=new ActiveXObject("Microsoft.XMLDOM");  
  3. }  
  4. else{  
  5.     if (document.implementation&& document.implementation.createDocument){  
  6.         var xmlDom= document.implementation.createDocument("","",null);  
  7.      }  
  8. }  


在使用DOM操作XML文件时,我们可以使用Load方法直接加载文件路径即可,在ie和ff下通用。但是如果传入的是XML字符串,则在两种浏览器下就会有所不同,IE下可以使用LoadXML方法直接调入下XML串,在FF下则不存在该方法,因此要使用W3CDom方式,具体如下:

[html] view plaincopy
  1. var oParser=new DOMParser();  
  2.    xmlDom=oParser.parseFromString(xmlStr,"text/xml");  


为兼容各种浏览器,我们这样去做即可:

[html] view plaincopy
    1. try{  
    2.   if (window.ActiveXObject){  
    3.     xmlDoc= new ActiveXObject("Microsoft.XMLDOM");  
    4.     xmlDoc.async = false;    
    5.     isLoaded = xmlDoc.load(aXMLFileName);   
    6.   }   
    7.   else if  
    8.      (document.implementation&& document.implementation.createDocument){  
    9.         try{    
    10.             xmlDoc = document.implementation.createDocument(‘‘, ‘‘, null);    
    11.             xmlDoc.async = false;    
    12.             xmlDoc.load(aXMLFileName);    
    13.         } catch(e){    
    14.             var xmlhttp = new window.XMLHttpRequest();    
    15.             xmlhttp.open("GET",aXMLFileName,false);    
    16.             xmlhttp.send(null);    
    17.             xmlDoc = xmlhttp.responseXML;    
    18.         }    
    19.   }  
    20.   else{  
    21.       alert("load data error");  
    22.   }  
    23.   }  
    24.   catch(e){  
    25.     alert(e.message);  
    26.   } 

(转)如何让ActiveXObject( "Microsoft.XmlDom ")对象在非IE浏览器下显示数据?firefox(火狐)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.