<div class="codetitle"> <span><a style="CURSOR: pointer" data="96612" class="copybut" id="copybut96612" onclick="doCopy('code96612')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code96612"> <br><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <br><html><head> <br><title> New Document </title> <br></head> <br><script language="javascript"> <br>function RunOnBeforeUnload() {window.onbeforeunload = function(){ return '将丢失未保存的数据!'; } } <br></script> <br><body onload="RunOnBeforeUnload()"> <br>刷新,关闭,后退,F5 测试 <br></body> <br></html><br> </div> <br>虽然onbeforeunload这个事件已经Web标准被淘汰,但目前能实现这个效果的也就只有这个事件.还好浏览器都能很好的支持.