尝试这个:<script>window.onbeforeunload = function (e) { e = e || window.event; // For IE and Firefox prior to version 4 if (e) { e.returnValue = 'Sure?'; } // For Safari return 'Sure?';};</script>
我读了关于设置为“ 好的”的答案的评论。大多数用户要求按钮和某些链接单击。这里,将在现有代码中再增加一行。<script type="text/javascript"> var hook = true; window.onbeforeunload = function() { if (hook) { return "Did you save your stuff?" } } function unhook() { hook=false; }调用unhook()onClick查找要允许的按钮和链接。例如<a href="#" onClick="unhook()">This link will allow navigation</a>