阻止默认事件
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","#");
}
});

相关文章:

  • 2021-12-14
  • 2021-06-16
  • 2022-12-23
  • 2021-08-15
  • 2021-08-16
  • 2021-05-17
  • 2020-06-12
猜你喜欢
  • 2022-12-23
  • 2022-02-27
  • 2022-01-17
  • 2022-12-23
  • 2021-12-28
相关资源
相似解决方案