惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
S
Securelist
P
Proofpoint News Feed
D
DataBreaches.Net
Cisco Talos Blog
Cisco Talos Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
Project Zero
Project Zero
A
About on SuperTechFans
罗磊的独立博客
WordPress大学
WordPress大学
月光博客
月光博客
Latest news
Latest news
C
Cyber Attacks, Cyber Crime and Cyber Security
GbyAI
GbyAI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
博客园 - 三生石上(FineUI控件)
F
Fortinet All Blogs
W
WeLiveSecurity
Attack and Defense Labs
Attack and Defense Labs
V
Visual Studio Blog
Blog — PlanetScale
Blog — PlanetScale
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
P
Privacy International News Feed
AI
AI
博客园 - 司徒正美
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Stack Overflow Blog
Stack Overflow Blog
M
MIT News - Artificial intelligence
Help Net Security
Help Net Security
T
Tor Project blog
V
Vulnerabilities – Threatpost
C
Cisco Blogs
I
Intezer
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
MyScale Blog
MyScale Blog
雷峰网
雷峰网
MongoDB | Blog
MongoDB | Blog
Forbes - Security
Forbes - Security
V
V2EX
Apple Machine Learning Research
Apple Machine Learning Research
T
Threat Research - Cisco Blogs
B
Blog RSS Feed
博客园 - 叶小钗
N
News and Events Feed by Topic
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Simon Willison's Weblog
Simon Willison's Weblog
C
CERT Recently Published Vulnerability Notes
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
N
News and Events Feed by Topic

博客园 - buru

django begining Update 两个表之间更新数据问题 用户控件与应用页面的事件顺序 linq小问题总结 “尝试读取或写入受保护的内存”错误处理 firefox浏览器的默认事件 配置rails运行环境 通过c#和ironruby学习 ruby语言 SQL 语句查询与性能 操作Access数据库碰到的几个问题 asp.net的CodeDom zz天涯-关于职业生涯的 一个线程管理器 zz两个存储过程 看《C#线程参考手册》 Mediator 中介者模式 IE与firefox取得事件对象的函数(zz) proxy模式 c#通过url获取文件
让firefox支持IE的一些属性
buru · 2007-09-30 · via 博客园 - buru

2007-09-30 14:05  buru  阅读(570)  评论()    收藏  举报

IE有很多好用的扩展是firefox 不支持的,比如firefox不支持children属性,还有很多,网上见到一些扩张的代码,摘录如下

<script language="JavaScript" type="Text/JavaScript">
<!--
if(window.Event){// 修正Event的DOM
    /*
                                IE5        MacIE5        Mozilla        Konqueror2.2        Opera5
    event                        yes        yes            yes            yes                    yes
    event.returnValue            yes        yes            no            no                    no
    event.cancelBubble            yes        yes            no            no                    no
    event.srcElement            yes        yes            no            no                    no
    event.fromElement            yes        yes            no            no                    no
    
    
*/

    Event.prototype.__defineSetter__(
"returnValue",function(b){// 
        if(!b)this.preventDefault();
        
return b;
        }
);
    Event.prototype.__defineSetter__(
"cancelBubble",function(b){// 设置或者检索当前事件句柄的层次冒泡
        if(b)this.stopPropagation();
        
return b;
        }
);
    Event.prototype.__defineGetter__(
"srcElement",function(){
        
var node=this.target;
        
while(node.nodeType!=1)node=node.parentNode;
        
return node;
        }
);
    Event.prototype.__defineGetter__(
"fromElement",function(){// 返回鼠标移出的源节点
        var node;
        
if(this.type=="mouseover")
            node
=this.relatedTarget;
        
else if(this.type=="mouseout")
            node
=this.target;
        
if(!node)return;
        
while(node.nodeType!=1)node=node.parentNode;
        
return node;
        }
);
    Event.prototype.__defineGetter__(
"toElement",function(){// 返回鼠标移入的源节点
        var node;
        
if(this.type=="mouseout")
            node
=this.relatedTarget;
        
else if(this.type=="mouseover")
            node
=this.target;
        
if(!node)return;
        
while(node.nodeType!=1)node=node.parentNode;
        
return node;
        }
);
    Event.prototype.__defineGetter__(
"offsetX",function(){
        
return this.layerX;
        }
);
    Event.prototype.__defineGetter__(
"offsetY",function(){
        
return this.layerY;
        }
);
    }

if(window.Document){// 修正Document的DOM
    /*
                                IE5        MacIE5        Mozilla        Konqueror2.2        Opera5
    document.documentElement    yes        yes            yes            yes                    no
    document.activeElement        yes        null        no            no                    no
    
    
*/

    }

if(window.Node){// 修正Node的DOM
    /*
                                IE5        MacIE5        Mozilla        Konqueror2.2        Opera5
    Node.contains                yes        yes            no            no                    yes
    Node.replaceNode            yes        no            no            no                    no
    Node.removeNode                yes        no            no            no                    no
    Node.children                yes        yes            no            no                    no
    Node.hasChildNodes            yes        yes            yes            yes                    no
    Node.childNodes                yes        yes            yes            yes                    no
    Node.swapNode                yes        no            no            no                    no
    Node.currentStyle            yes        yes            no            no                    no
    
    
*/

    Node.prototype.replaceNode
=function(Node){// 替换指定节点
        this.parentNode.replaceChild(Node,this);
        }

    Node.prototype.removeNode
=function(removeChildren){// 删除指定节点
        if(removeChildren)
            
return this.parentNode.removeChild(this);
        
else{
            
var range=document.createRange();
            range.selectNodeContents(
this);
            
return this.parentNode.replaceChild(range.extractContents(),this);
            }

        }

    Node.prototype.swapNode
=function(Node){// 交换节点
        var nextSibling=this.nextSibling;
        
var parentNode=this.parentNode;
        node.parentNode.replaceChild(
this,Node);
        parentNode.insertBefore(node,nextSibling);
        }

    }

if(window.HTMLElement){
    HTMLElement.prototype.__defineGetter__(
"all",function(){
        
var a=this.getElementsByTagName("*");
        
var node=this;
        a.tags
=function(sTagName){
            
return node.getElementsByTagName(sTagName);
            }

        
return a;
        }
);
    HTMLElement.prototype.__defineGetter__(
"parentElement",function(){
        
if(this.parentNode==this.ownerDocument)return null;
        
return this.parentNode;
        }
);
    HTMLElement.prototype.__defineGetter__(
"children",function(){
        
var tmp=[];
        
var j=0;
        
var n;
        
for(var i=0;i<this.childNodes.length;i++){
            n
=this.childNodes[i];
            
if(n.nodeType==1){
                tmp[j
++]=n;
                
if(n.name){
                    
if(!tmp[n.name])
                        tmp[n.name]
=[];
                    tmp[n.name][tmp[n.name].length]
=n;
                    }

                
if(n.id)
                    tmp[n.id]
=n;
                }

            }

        
return tmp;
        }
);
    HTMLElement.prototype.__defineGetter__(
"currentStyle"function(){
        
return this.ownerDocument.defaultView.getComputedStyle(this,null);
        }
);
    HTMLElement.prototype.__defineSetter__(
"outerHTML",function(sHTML){
        
var r=this.ownerDocument.createRange();
        r.setStartBefore(
this);
        
var df=r.createContextualFragment(sHTML);
        
this.parentNode.replaceChild(df,this);
        
return sHTML;
        }
);
    HTMLElement.prototype.__defineGetter__(
"outerHTML",function(){
        
var attr;
        
var attrs=this.attributes;
        
var str="<"+this.tagName;
        
for(var i=0;i<attrs.length;i++){
            attr
=attrs[i];
            
if(attr.specified)
                str
+=" "+attr.name+'="'+attr.value+'"';
            }

        
if(!this.canHaveChildren)
            
return str+">";
        
return str+">"+this.innerHTML+"</"+this.tagName+">";
        }
);
    HTMLElement.prototype.__defineGetter__(
"canHaveChildren",function(){
        
switch(this.tagName.toLowerCase()){
            
case "area":
            
case "base":
            
case "basefont":
            
case "col":
            
case "frame":
            
case "hr":
            
case "img":
            
case "br":
            
case "input":
            
case "isindex":
            
case "link":
            
case "meta":
            
case "param":
                
return false;
            }

        
return true;
        }
);

    HTMLElement.prototype.__defineSetter__(
"innerText",function(sText){
        
var parsedText=document.createTextNode(sText);
        
this.innerHTML=parsedText;
        
return parsedText;
        }
);
    HTMLElement.prototype.__defineGetter__(
"innerText",function(){
        
var r=this.ownerDocument.createRange();
        r.selectNodeContents(
this);
        
return r.toString();
        }
);
    HTMLElement.prototype.__defineSetter__(
"outerText",function(sText){
        
var parsedText=document.createTextNode(sText);
        
this.outerHTML=parsedText;
        
return parsedText;
        }
);
    HTMLElement.prototype.__defineGetter__(
"outerText",function(){
        
var r=this.ownerDocument.createRange();
        r.selectNodeContents(
this);
        
return r.toString();
        }
);
    HTMLElement.prototype.attachEvent
=function(sType,fHandler){
        
var shortTypeName=sType.replace(/on/,"");
        fHandler._ieEmuEventHandler
=function(e){
            window.event
=e;
            
return fHandler();
            }

        
this.addEventListener(shortTypeName,fHandler._ieEmuEventHandler,false);
        }

    HTMLElement.prototype.detachEvent
=function(sType,fHandler){
        
var shortTypeName=sType.replace(/on/,"");
        
if(typeof(fHandler._ieEmuEventHandler)=="function")
            
this.removeEventListener(shortTypeName,fHandler._ieEmuEventHandler,false);
        
else
            
this.removeEventListener(shortTypeName,fHandler,true);
        }

    HTMLElement.prototype.contains
=function(Node){// 是否包含某节点
        do if(Node==this)return true;
        
while(Node=Node.parentNode);
        
return false;
        }

    HTMLElement.prototype.insertAdjacentElement
=function(where,parsedNode){
        
switch(where){
            
case "beforeBegin":
                
this.parentNode.insertBefore(parsedNode,this);
                
break;
            
case "afterBegin":
                
this.insertBefore(parsedNode,this.firstChild);
                
break;
            
case "beforeEnd":
                
this.appendChild(parsedNode);
                
break;
            
case "afterEnd":
                
if(this.nextSibling)
                    
this.parentNode.insertBefore(parsedNode,this.nextSibling);
                
else
                    
this.parentNode.appendChild(parsedNode);
                
break;
            }

        }

    HTMLElement.prototype.insertAdjacentHTML
=function(where,htmlStr){
        
var r=this.ownerDocument.createRange();
        r.setStartBefore(
this);
        
var parsedHTML=r.createContextualFragment(htmlStr);
        
this.insertAdjacentElement(where,parsedHTML);
        }

    HTMLElement.prototype.insertAdjacentText
=function(where,txtStr){
        
var parsedText=document.createTextNode(txtStr);
        
this.insertAdjacentElement(where,parsedText);
        }

    HTMLElement.prototype.attachEvent
=function(sType,fHandler){
        
var shortTypeName=sType.replace(/on/,"");
        fHandler._ieEmuEventHandler
=function(e){
            window.event
=e;
            
return fHandler();
            }

        
this.addEventListener(shortTypeName,fHandler._ieEmuEventHandler,false);
        }

    HTMLElement.prototype.detachEvent
=function(sType,fHandler){
        
var shortTypeName=sType.replace(/on/,"");
        
if(typeof(fHandler._ieEmuEventHandler)=="function")
            
this.removeEventListener(shortTypeName,fHandler._ieEmuEventHandler,false);
        
else
            
this.removeEventListener(shortTypeName,fHandler,true);
        }

    }

//-->
</script>


原文链接: http://www.dubox.cn/Trackback.aspx?id=27