iframe监听unload事件

阻止默认事件
event.preventDefault();
阻止事件冒泡
event.stopPropagation();
event.cancelBubble = true; //IE


<a>标签会触发onbeforeunload事件,事件时间顺序 onclick > onbeforeunload > href
在onclick事件中rerun false后面的事件就不再执行
<a>标签的href为#时也不触发onbeforeunload事件。


父页面的unload和beforeunload会向iframe中传递。但是iframe中的beforeunload不会向上级页面传播


通过设置<a>标签的href为#来绕过onbeforeunload事件
$('a').live('mousedown',function(){
var href = $(this).attr('href');
if( href && $.trim(href).indexOf('javascript:') == 0 ){
if($.trim(href) != 'javascript:void(0)'){
$(this).bind('click',function(){eval($.trim(href).substring(11));}) ;
}
$(this).attr("href","#");
}
});
原文地址:https://www.cnblogs.com/vvch/p/4027572.html