`
ihibernate
  • 浏览: 150788 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

解决离开页面前onbeforeunload事件在火狐的兼容并且提交不触发

阅读更多
离开页面前onbeforeunload事件在火狐的兼容并且提交不触发

<html>
<head>
<script language="javascript">
	var thisPage=false;
	window.onbeforeunload=function checkLeave(e){
	var evt = e ? e : (window.event ? window.event : null);  //此方法为了在firefox中的兼容
		if(!thisPage)evt.returnValue='离开会使编写的内容丢失。';
	}
	function sumbit(){
	thisPage=true;
	document.getElementById('YourFormId').submit();
	}
</script>
</head>
<body>
<p><a href='http://www.baidu.com'>baidu.com</a></p>

  <form id='YourFormId' action='http://www.baidu.com'>
      <input type="button" name="button" id="button" value="提交" onclick="sumbit();"/>
  </form>
</body>
</html>
分享到:
评论
2 楼 aaron0768 2015-11-25  
第6行多了个e
1 楼 aaron0768 2015-11-25  
博主,我直接copy代码运行,跳转没提示~

相关推荐

Global site tag (gtag.js) - Google Analytics