<script>
var t;
window.onbeforeunload=function(){
setTimeout(function(){t=setTimeout(onunloadcancel,0)},0);
return "确认离开";
}
window.onunloadcancel=function(){
clearTimeout(t);//为了防止刷新执行两次
alert("取消离开');
</script>