解決離開頁面前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>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章