当用户点击另一个链接或刷新页面时,窗口会卸载,如何防止/确认?
答案 0 :(得分:7)
从这里http://bytes.com/topic/javascript/insights/825556-using-onbeforeunload-javascript-event
<script type="text/javascript">
window.onbeforeunload = function(){ return 'Your Returned String Goes Here';}
</script>
答案 1 :(得分:3)
我认为onbeforeunload事件处理程序将是您正在寻找的。 p>
尝试以下方法:
window.onbeforeunload = confirmExit;
function confirmExit()
{
return "You have attempted to leave this page. If you have made any changes to the fields without clicking the Save button, your changes will be lost. Are you sure you want to exit this page?";
}
答案 2 :(得分:0)
查看此page底部的卸载情况。