捕捉窗口关闭或内容改变事件
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<script>
window.onbeforeunload = saveBeforeExit;
function saveBeforeExit()
{
var result=confirm("Navigate away Without saving data?");
if (result==true)
{
//alert(document.frmIndex.hdnState2.value); alerts 'onloadvalue';
document.frmIndex.hdnState2.value ='Yes';
//alert(document.frmIndex.hdnState2.value); alerts 'Yes';
}
else
{
//alert(document.frmIndex.hdnState2.value); alerts 'onloadvalue';
document.frmIndex.hdnState2.value ='No';
//alert(document.frmIndex.hdnState2.value); alerts 'No';
}
return;
}
</script>
<body>
<form name="frmIndex">
<input type="hidden" name="hdnState2" value="onloadvalue">
</form>
</body>
</html>
<html>
<script>
window.onbeforeunload = saveBeforeExit;
function saveBeforeExit()
{
var result=confirm("Navigate away Without saving data?");
if (result==true)
{
//alert(document.frmIndex.hdnState2.value); alerts 'onloadvalue';
document.frmIndex.hdnState2.value ='Yes';
//alert(document.frmIndex.hdnState2.value); alerts 'Yes';
}
else
{
//alert(document.frmIndex.hdnState2.value); alerts 'onloadvalue';
document.frmIndex.hdnState2.value ='No';
//alert(document.frmIndex.hdnState2.value); alerts 'No';
}
return;
}
</script>
<body>
<form name="frmIndex">
<input type="hidden" name="hdnState2" value="onloadvalue">
</form>
</body>
</html>