jsp窗口关闭的触发函数
功能:当点击窗口【关闭按钮】时调用后台的servlet方法实现附件删除
<script type="text/javascript">
window.onbeforeunload = function() {
var n = window.event.screenX - window.screenLeft;
var b = n > document.documentElement.scrollWidth-20;
if(b && window.event.clientY < 0 || window.event.altKey){
alert("触发");
var nbbm = document.getElementById("policyID").value;
window.location.href='/PolicyPackage?tg=beforeCloseWin&nbbm='+nbbm;
}
}
</script>
onbeforeunload是离开本jsp页面就会触发该函数,包含页面的刷新、局部的触发都会收到影响。
因此添加
var n = window.event.screenX - window.screenLeft;
var b = n > document.documentElement.scrollWidth-20;
if(b && window.event.clientY < 0 || window.event.altKey){}
可以排除刷新 关闭的时候触发
=========================================================================
如果双击jsp关闭按钮后触发一个函数,可以参考下面代码实现:
window.onunload = onunload_handler;
function onunload_handler(){
var isSave = document.getElementById("isSave").value;
if(isSave=="false" ){
var nbbms = document.getElementById("attNBBM").value;
if(nbbms.length>0){
Ext.Ajax.request({
url:"/FangAnAttachment?action=return&nbbm="+nbbms
});
}
}
}