javascript在中ie与firefox的区别与解决方案
来源:互联网 发布:clear动作数据 编辑:程序博客网 时间:2024/05/01 06:08
javascript在中ie与firefox的区别
1.载入xml
ie创建对象:
msXmlAx=new ActiveXObject("Microsoft.XMLDOM");
firefox创建对象:
xDoc=document.implementation.createDocument("","",null);
总体方法为:
///判断浏览器 创建不同的对象
function getXmlDocument()
{
var xDoc;
if(document.implementation && document.implementation.createDocument)
{
xDoc=document.implementation.createDocument("","",null);
}
else if(typeof ActiveXObject !="undefined")
{
var msXmlAx=null;
try{
msXmlAx=new ActiveXObject("Microsoft.XMLDOM");
}
catch(e)
{
msXmlAx=new ActiveXObject ("Microsoft.XMLDOM");
}
xDoc=msXmlAx;
}
if(xDoc== null || typeof xDoc.load=="undefined")
{
xDoc=null;
}
return xDoc;
}
2.insertRow和insertCell
在ie中可直接调用该方法 document.getElementById("xxx").insertRow();
在firefox 中需要放置参数:document.getElementById("xxx").insertRow(-1);
同样 insertRow(-1)也支持ie
3.判断浏览器类型
/*---------------------------------------------------------------
--this function can return the actual browser name and version.--
--USESAGE:There are Two Methods(See the end of this function) --
--Create By Yemoo. DateTime:2006-2-3 21:53:37 --
---------------------------------------------------------------*/
function browserinfo(){
var Browser_Name=navigator.appName;
var Browser_Version=parseFloat(navigator.appVersion);
var Browser_Agent=navigator.userAgent;
var Actual_Version,Actual_Name;
var is_IE=(Browser_Name=="Microsoft Internet Explorer");
var is_NN=(Browser_Name=="Netscape");
if(is_NN){
//upper 5.0 need to be process,lower 5.0 return directly
if(Browser_Version>=5.0){
var Split_Sign=Browser_Agent.lastIndexOf("/");
var Version=Browser_Agent.indexOf(" ",Split_Sign);
var Bname=Browser_Agent.lastIndexOf(" ",Split_Sign);
Actual_Version=Browser_Agent.substring(Split_Sign+1,Version);
Actual_Name=Browser_Agent.substring(Bname+1,Split_Sign);
}
else{
Actual_Version=Browser_Version;
Actual_Name=Browser_Name;
}
}
else if(is_IE){
var Version_Start=Browser_Agent.indexOf("MSIE");
var Version_End=Browser_Agent.indexOf(";",Version_Start);
Actual_Version=Browser_Agent.substring(Version_Start+5,Version_End)
Actual_Name=Browser_Name;
if(Browser_Agent.indexOf("Maxthon")!=-1){
Actual_Name+="(Maxthon)";
}
else if(Browser_Agent.indexOf("Opera")!=-1){
Actual_Name="Opera";
var tempstart=Browser_Agent.indexOf("Opera");
var tempend=Browser_Agent.length;
Actual_Version=Browser_Agent.substring(tempstart+6,tempend)
}
}
else{
Actual_Name="Unknown Navigator"
Actual_Version="Unknown Version"
}
/*------------------------------------------------------------------------------
--Your Can Create new properties of navigator(Acutal_Name and Actual_Version) --
--Userage: --
--1,Call This Function. --
--2,use the property Like This:navigator.Actual_Name/navigator.Actual_Version;--
------------------------------------------------------------------------------*/
navigator.Actual_Name=Actual_Name;
navigator.Actual_Version=Actual_Version;
/*---------------------------------------------------------------------------
--Or Made this a Class. --
--Userage: --
--1,Create a instance of this object like this:var browser=new browserinfo;--
--2,user this instance:browser.Version/browser.Name; --
---------------------------------------------------------------------------*/
this.Name=Actual_Name;
this.Version=Actual_Version;
}
通过: navigator.Actual_Name 得到浏览器名称,navigator.Actual_Version 的到浏览器版本
4. firefox 中无法像ie一样通过documentElement得到xml文本对象的所有元素信息,可以使用替换法:
创建XMLHttpRequest对象,通过它的responseXML返回的xml对象进行操作
5.firefox中不支持window.event
解决方法:
document.onclick=function(e) //要兼容ff的话,这个参数一定要写上
{
e = window.event || e;
e = e.srcElement || e.target;
//其他实现代码
}
6.firefox不支持parentElement,若要使用可写成:parentNode
7.IE中将xml通过xsl进行格式化时,使用如下代码:
xmlDoc.transformNode(xslDoc);
xmlDoc为xml文档
xslDoc为xsl文档
在firefox中使用如下代码:
var xsltProcessor =new XSLTProcessor();
xsltProcessor.importStylesheet(xslDoc);
var resultHtml= xsltProcessor.transformToDocument(xmlDoc);
var oXmlSerializer = new XMLSerializer();
$GetEle("ZfDiv_").innerHTML= oXmlSerializer.serializeToString(resultHtml);
[未完待续。。。。]
-------------
因为是自己的总结的 如果有什么问题,还望大家提出来
- javascript在中ie与firefox的区别与解决方案
- javascript在中ie与firefox的区别与解决方案
- JavaScript中IE与Firefox的区别
- javascript 在IE与firefox中的区别
- IE与firefox在Javascript上的区别
- IE与FireFox在javascript中兼容性问题
- firefox与ie 的javascript区别
- firefox与ie 的javascript区别
- firefox与ie 的javascript区别
- firefox与ie 的javascript区别
- firefox与ie 的javascript区别
- firefox与ie的javascript区别
- IE与FireFox应用javascript的区别
- firefox与ie 的javascript区别
- firefox与ie 的javascript区别
- firefox与ie 的javascript区别
- JS中select在firefox与ie之间的区别
- IE与Firefox在处理html中Alt的区别
- Delphi中的Win32 API应用六例
- 看网友如何展望ERP未来
- 提高库存信息的精度是仓库效率的关键
- Helix简介
- The Open-Closed Principle (OCP) - 面向对象软件设计的开闭原则
- javascript在中ie与firefox的区别与解决方案
- Office 2007 SP1 和 Vista Service Pack 1 RC和XP SP3英文自解压版本已经提供下载
- 电信主要公司简介zz
- 某高级网站开发工程师的要求,自己可以对比一下自己的情况
- 中国最有气势的诗句
- xmms播放清单中文乱码问题
- java中带包的编译运行方法
- 必须知道的社会生活中十二大著名法则
- Lesson 71 He's awful.