IE下,如果在a标签的href中设置了javascript:,则会自动调用onbeforeunload事件
此外,
父容器包含一个iframe,在父容器中设置onbeforeunload事件不会影响iframe中的内容,但在iframe中进一步动态生成形如<a href="javascript:"的内容,则会绑定onbeforeunload事件
测试用例:
1.html
2.html
此外,
父容器包含一个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 >
< a href ="javascript:" > 点击测试javascript: </ a >
< a href ="#this" > 点击测试#this </ a >
< iframe src ="2.html" style ="width:200px;height:200px;" >
</ iframe >
</ body >
</ html >
"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 >
< a href ="javascript:" > 点击测试javascript: </ a >
< 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 >
< a href ="javascript:this.innerHTML='<a href='javascrpt:'>我有事</a>'" > 我没事 </ a >
</ body >
</ html >
"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 >
< a href ="javascript:this.innerHTML='<a href='javascrpt:'>我有事</a>'" > 我没事 </ a >
</ body >
</ html >