标签自动绑定onbeforeunload事件的问题

IE下,如果在a标签的href中设置了javascript:,则会自动调用onbeforeunload事件
此外,
父容器包含一个iframe,在父容器中设置onbeforeunload事件不会影响iframe中的内容,但在iframe中进一步动态生成形如<a href="javascript:"的内容,则会绑定onbeforeunload事件

测试用例:
1.html
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
< html   xmlns ="http://www.w3.org/1999/xhtml"  lang ="utf-8"  xml:lang ="utf-8" >
    
< head >
        
< title > MySpace.cn </ title >
    
</ head >
    
< script  type ="text/javascript" >
        
var MSG_UNLOAD="您的文章内容还没有进行保存!";
        
var UnloadConfirm = {};

        UnloadConfirm.set 
= function(confirm_msg){
            window.onbeforeunload 
= function(event){
                event 
= event || window.event;
                event.returnValue 
= confirm_msg;
            }


        }

        UnloadConfirm.clear 
= function(){
            window.onbeforeunload 
= function(){};
        }

        UnloadConfirm.set(MSG_UNLOAD);
    
</ script >
    
< body >
        
< href ="javascript:" > 点击测试javascript: </ a >
        
< href ="#this" > 点击测试#this </ a >
        
< iframe  src ="2.html"  style ="width:200px;height:200px;" >
        
</ iframe >
    
</ body >
</ html >

2.html
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
< html   xmlns ="http://www.w3.org/1999/xhtml"  lang ="utf-8"  xml:lang ="utf-8" >
    
< head >
        
< title > MySpace.cn </ title >
    
</ head >
    
< body >
        
< href ="javascript:this.innerHTML='<a href='javascrpt:'>我有事</a>'" > 我没事 </ a >
    
</ body >
</ html >
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值