這是本文件的舊版!
http://blog.darkthread.net/post-2011-07-26-prevent-backspace-goback-in-browser.aspx
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.2.js" type="text/javascript"></script> <script type="text/javascript"> $(function () { //除了input text外,停用Backsapce,防止不慎回前一頁 $(document).keydown(function (e) { //採用demo建議 多考量"textarea" if (e.which == 8 && (e.target.type == "text" || e.target.type == "textarea")) e.preventDefault(); }); }); </script>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.2.js" type="text/javascript"></script> <script type="text/javascript"> $(function () { function setUnloadWarning(enabled) { window.onbeforeunload = enabled ? showWarning : null; } function showWarning() { return "資料尚未儲存,確定要離開嗎?" } $("input:text").live("change", function () { setUnloadWarning(true); }); $("input:submit").click(function () { setUnloadWarning(false); }); }); </script>