解决离开页面前onbeforeunload事件在火狐的兼容并且提交不触发
离开页面前onbeforeunload事件在火狐的兼容并且提交不触发
Html代码- 1.<html>
- 2.<head>
- 3.<script language="javascript">
- 4. var thisPage=false;
- 5. window.onbeforeunload=function checkLeave(e){
- 6. var eevt = e ? e : (window.event ? window.event : null); //此方法为了在firefox中的兼容
- 7. if(!thisPage)evt.returnValue='离开会使编写的内容丢失。';
- 8. }
- 9. function sumbit(){
- 10. thisPage=true;
- 11. document.getElementById('YourFormId').submit();
- 12. }
- 13.</script>
- 14.</head>
- 15.<body>
- 16.<p><a href='http://www.baidu.com'>baidu.com</a></p>
- 17.
- 18. <form id='YourFormId' action='http://www.baidu.com'>
- 19. <input type="button" name="button" id="button" value="提交" onclick="sumbit();"/>
- 20. </form>
- 21.</body>
- 22.</html>
复制代码 |