{ var n = window.event.screenX - window.screenLeft; var b = n > document.documentElement.scrollWidth-20; if(b && window.event.clientY < 0 || window.event.altKey) { alert("关闭浏览器事件"); //这里可以放置你想做的操作代码 } }
<script language="JavaScript" type="text/javascript">
window.onbeforeunload = CloseEvent;
var DispClose = true;
function CloseEvent()
{
if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){
if (DispClose)
{
return "是否离开当前页面?";
}
}
}
window.onunload= UnLoadEvent;
function UnLoadEvent()
{if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){
DispClose = false;
//在这里处理关闭页面前的动作
window.close();
}
}
</script>
如果是其他页面离开的话就不做上面的 window.close处理
只要将 onunload 设为null 就可以了 window.onunload= null;
function submittest(){
// var pfv = parseInt($("#pf").html());
var pfv = 5;
if(rms < pfv){
$("#dialog-time").html("考试时间不足"+pfv+"秒,不能交卷!");
$("#dialog-time").dialog("open");
}else{
var qf = parseInt($("#qf").html());
if(qf>0 && parseInt(lms)){
window.onunload= null;
$("#dialog-confirm").html("您还有"+qf+"道试题未做,是否继续交卷!");
$("#dialog-confirm").dialog("open");
}else{
return submital();
}
}
}