[code lang=”js”]
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("是关闭而非刷新");
 //window.event.returnValue = "是否关闭?";
 }else{
 // alert("是刷新而非关闭");
 if(document.getElementById(‘content’).value!=”){
 window.event.returnValue = ‘刷新后将丢失现有的日记内容,确认刷新?’;
 }
 }
}
[/code]
