在HTML页面中添加如下代码:
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) { var vote = parseInt("<%=canVote-usedVote%>"); if(vote>0 && "false"=="<%=isRead%>"){ window.event.returnValue = "您还有"+surplus+"次可投票的机会,是否确认放弃投票?"; } }else{ //alert("是刷新而非关闭"); } }