$(window).unbind("beforeunload");
 
http://www.iteye.com/problems/88231

如何取消jquery或js的onbeforeunload事件的默认弹窗15

如何取消jquery或js的onbeforeunload事件的默认弹窗,在事件出发后,浏览器会默认弹出一个提示框,可以选择留在此页或离开,请问如何屏蔽这个弹窗,因为需求有个自定义的样式图片和按钮来进行这个操作,坐等解答
2012年9月10日 16:09
 
 
 

2个答案按时间排序按投票排序

00

关闭不默认弹窗 

Javascript代码  收藏代码
  1. window.onbeforeunload ='';  
  2.         window.open(' ''_self'' ');   
  3.         window.close();  

 

2012年9月10日 17:25
 
00

<!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"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
</head> 
<script type="text/javascript" src="jquery-1.4.2.js"></script> 
<script type="text/javascript"> 
$(window).bind('beforeunload', function(){ 
  return '确认离开此页吗'; 
}); 

</script> 
<body> 

<input type="button" value="取消beforeunload" onclick='$(window).unbind("beforeunload");'> 

</body> 
</html>