目前我正在嘗試使用ASP.NET MVC5構建一個網站。 我被卡住了。如何限制用戶導航回到上一頁並刷新?
問題:我希望當用戶轉到特定頁面時,他/她不應該能夠刷新頁面,返回到上一頁,複製任何內容,打印屏幕。
嘗試了多種不同的解決方案,如如下:
window.onload = function() {
if (typeof history.pushState === "function") {
history.pushState("jibberish", null, null);
window.onpopstate = function() {
history.pushState('newjibberish', null, null);
// Handle the back (or forward) buttons here
// Will NOT handle refresh, use onbeforeunload for this.
};
}
else {
var ignoreHashChange = true;
window.onhashchange = function() {
if (!ignoreHashChange) {
ignoreHashChange = true;
window.location.hash = Math.random();
// Detect and redirect change here
// Works in older FF and IE9
// * it does mess with your hash symbol (anchor?) pound sign
// delimiter on the end of the URL
}
else {
ignoreHashChange = false;
}
};
}
}
<script type="text/javascript">
window.onbeforeunload = function() {
return "Dude, are you sure you want to leave? Think of the kittens!";
}
</script>
<script type="text/javascript">
function disableF5(e) { if ((e.which || e.keyCode) == 116 || (e.which || e.keyCode) == 82) e.preventDefault(); };
$(document).ready(function(){
$(document).on("keydown", disableF5);
});
</script>
但沒有什麼似乎工作。
請建議。
「我想要當用戶轉到特定頁面時,他/她不應該刷新頁面,返回到上一頁,複製任何內容,打印屏幕「;你確定你真的想要一個網絡應用程序嗎? – dandavis 2015-02-08 06:42:44
是的。當他/她參加考試時,它會想要一個頁面。 – priyam 2015-02-08 06:44:47