1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > javascript firefox兼容ie的dom方法脚本【javascript】

javascript firefox兼容ie的dom方法脚本【javascript】

时间:2019-04-23 09:55:42

相关推荐

javascript firefox兼容ie的dom方法脚本【javascript】

web前端|js教程

javascript,firefox,兼容ie,dom方法,脚本

web前端-js教程

if(!document.all){

//zzcv的ff ie兼容脚本

/*脚本没有解决的问题及处理:

整站源码克隆器,更改ubuntu终端背景,吃爬虫的说说,dedecms php,seo结构推荐lzw

2.IE下,可以使用()或[]获取集合类对象;Firefox下,只能使用[]获取集合类对象.

解决方法:统一使用[]获取集合类对象.

3.IE下,可以使用获取常规属性的方法来获取自定义属性,也可以使用getAttribute()获取自定义属性;Firefox下,只能使用getAttribute()获取自定义属性.

解决方法:统一通过getAttribute()获取自定义属性.

4.IE下,HTML对象的ID可以作为document的下属对象变量名直接使用;Firefox下则不能.

5.Firefox下,可以使用与HTML对象ID相同的变量名;IE下则不能。

解决方法:使用document.getElementById(“idName”)代替document.idName.最好不要取HTML对象ID相同的变量名,以减少错误;在声明变量时,一律加上var,以避免歧义.

6.IE下input.type属性为只读;但是Firefox下input.type属性为读写.

8.IE下,可以通过showModalDialog和showModelessDialog打开模态和非模态窗口;Firefox下则不能

9.Firefox的body在body标签没有被浏览器完全读入之前就存在;而IE的body则必须在body标签被浏览器完全读入之后才存在

10.

*/

//文档兼容

HTMLDocument.prototype.__defineGetter__(“all”,function(){

return this.getElementsByName(“*”);});

行政办公系统源码下载,用vscode开发js,ubuntu 拍照代码,tomcat bio假死,sqlite3创建表查询,网络爬虫与数据分析实验,php传输数据,北京SEO刻羽云,搭建一个拍卖网站源码,网页边框绿色,闲鱼公告模板lzw

HTMLFormElement.constructor.prototype.item=function(s){

return this.elements[s];};

易吃cms源码,vscode 连接vsts,红警ubuntu,tomcat优化禁用,sqlite有密码吗,wordpress弹出框插件,开源跨平台前端框架,爬虫爬取指定信息,php 格式 字符串,seo必学的八个技术seo教程,个人网站支付功能,网页图片切换代码,企业贷款模板lzw

HTMLCollection.prototype.item=function(s){

return this[s];};

//事件兼容

window.constructor.prototype.__defineGetter__(“event”,function(){

for(var o=arguments.callee.caller,e=null;o!=null;o=o.caller){

e=o.arguments[0];

if(e&&(e instanceof Event))

return e;}

return null;});

window.constructor.prototype.attachEvent=HTMLDocument.prototype.attachEvent=HTMLElement.prototype.attachEvent=function(e,f){

this.addEventListener(e.replace(/^on/i,””),f,false);};

window.constructor.prototype.detachEvent=HTMLDocument.prototype.detachEvent=HTMLElement.prototype.detachEvent=function(e,f){

this.removeEventListener(e.replace(/^on/i,””),f,false);};

with(window.Event.constructor.prototype){

__defineGetter__(“srcElement”,function(){

return this.target;});

__defineSetter__(“returnValue”,function(b){

if(!b)this.preventDefault();});

__defineSetter__(“cancelBubble”,function(b){

if(b)this.stopPropagation();});

__defineGetter__(“fromElement”,function(){

var o=(this.type==”mouseover”&&this.relatedTarget)||(this.type==”mouseout”&&this.target)||null;

if(o)

while(o.nodeType!=1)

o=o.parentNode;

return o;});

__defineGetter__(“toElement”,function(){

var o=(this.type==”mouseover”&&this.target)||(this.type==”mouseout”&&this.relatedTarget)||null;

if(o)

while(o.nodeType!=1)

o=o.parentNode;

return o;});

__defineGetter__(“x”,function(){

return this.pageX;});

__defineGetter__(“y”,function(){

return this.pageY;});

__defineGetter__(“offsetX”,function(){

return this.layerX;});

__defineGetter__(“offsetY”,function(){

return this.layerY;});

}

//节点操作兼容

with(window.Node.prototype){

replaceNode=function(o){

this.parentNode.replaceChild(o,this);}

removeNode=function(b){

if(b)

return this.parentNode.removeChild(this);

var range=document.createRange();

range.selectNodeContents(this);

return this.parentNode.replaceChild(range.extractContents(),this);}

swapNode=function(o){

return this.parentNode.replaceChild(o.parentNode.replaceChild(this,o),this);}

contains=function(o){

return o?((o==this)?true:arguments.callee(o.parentNode)):false;}

}

//HTML元素兼容

with(window.HTMLElement.prototype){

__defineGetter__(“parentElement”,function(){

return (this.parentNode==this.ownerDocument)?null:this.parentNode;});

__defineGetter__(“children”,function(){

var c=[];

for(var i=0,cs=this.childNodes;i<cs.length;i++){

if(cs[i].nodeType==1)

c.push(cs[i]);}

return c;});

__defineGetter__(“canHaveChildren”,function(){

return !/^(area|base|basefont|col|frame|hr|img|br|input|isindex|link|meta|param)$/i.test(this.tagName);});

__defineSetter__(“outerHTML”,function(s){

var r=this.ownerDocument.createRange();

r.setStartBefore(this);

void this.parentNode.replaceChild(r.createContextualFragment(s),this);

return s;});

__defineGetter__(“outerHTML”,function(){

var as=this.attributes;

var str=”<"+this.tagName;

for(var i=0,al=as.length;i if(as[i].specified)

str+=” “+as[i].name+”=””+as[i].value+”””;}

return this.canHaveChildren?str+”>”:str+”>”+this.innerHTML+””;});

__defineSetter__(“innerText”,function(s){

return this.innerHTML=document.createTextNode(s);});

__defineGetter__(“innerText”,function(){

var r=this.ownerDocument.createRange();

r.selectNodeContents(this);

return r.toString();});

__defineSetter__(“outerText”,function(s){

void this.parentNode.replaceChild(document.createTextNode(s),this);

return s});

__defineGetter__(“outerText”,function(){

var r=this.ownerDocument.createRange();

r.selectNodeContents(this);

return r.toString();});

insertAdjacentElement=function(s,o){

return (s==”beforeBegin”&&this.parentNode.insertBefore(o,this))||(s==”afterBegin”&&this.insertBefore(o,this.firstChild))||(s==”beforeEnd”&&this.appendChild(o))||(s==”afterEnd”&&((this.nextSibling)&&this.parentNode.insertBefore(o,this.nextSibling)||this.parentNode.appendChild(o)))||null;}

insertAdjacentHTML=function(s,h){

var r=this.ownerDocument.createRange();

r.setStartBefore(this);

this.insertAdjacentElement(s,r.createContextualFragment(h));}

insertAdjacentText=function(s,t){

this.insertAdjacentElement(s,document.createTextNode(t));}

}

//XMLDOM兼容

window.ActiveXObject=function(s){

switch(s){

case “XMLDom”:

document.implementation.createDocument.call(this,”text/xml”,””, null);

//domDoc = document.implementation.createDocument(“text/xml”,””, null);

break;

}

}

XMLDocument.prototype.LoadXML=function(s){

for(var i=0,cs=this.childNodes,cl=childNodes.length;i<cl;i++)

this.removeChild(cs[i]);

this.appendChild(this.importNode((new DOMParser()).parseFromString(s,”text/xml”).documentElement,true));}

XMLDocument.prototype.selectSingleNode=Element.prototype.selectSingleNode=function(s){

return this.selectNodes(s)[0];}

XMLDocument.prototype.selectNodes=Element.prototype.selectNodes=function(s){

var rt=[];

for(var i=0,rs=this.evaluate(s,this,this.createNSResolver(this.ownerDocument==null?this.documentElement:this.ownerDocument.documentElement),XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),sl=rs.snapshotLength;i<sl;i++)

rt.push(rs.snapshotItem(i));

return rt;}

XMLDocument.prototype.__proto__.__defineGetter__(“xml”,function(){

try{

return new XMLSerializer().serializeToString(this);}

catch(e){

return document.createElement(“div”).appendChild(this.cloneNode(true)).innerHTML;}});

Element.prototype.__proto__.__defineGetter__(“xml”,function(){

try{

return new XMLSerializer().serializeToString(this);}

catch(e){

return document.createElement(“div”).appendChild(this.cloneNode(true)).innerHTML;}});

XMLDocument.prototype.__proto__.__defineGetter__(“text”,function(){

return this.firstChild.textContent;});

Element.prototype.__proto__.__defineGetter__(“text”,function(){

return this.textContent;});

Element.prototype.__proto__.__defineSetter__(“text”,function(s){

return this.textContent=s;});

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。