在asp.net应用程序中禁用浏览器关闭按钮?

问题描述:

我正在做在线考试应用程序使用asp.net在这我必须禁用标题栏,以便用户没有选择退出与时间period.So请帮助这一个在asp.net应用程序中禁用浏览器关闭按钮?

+3

http://*.com/help/how-to-ask检查此 – Dandy

它不是很好的做法强制用户在网页上停留,如果他们不希望,但你可以有周围的一些工作,如果你想他们离开之前的浏览器选项卡

function internalHandler(e) { 
    return "Please don't leave the page you can be fail in exams!"; 
} 
if (window.addEventListener) { 
    window.addEventListener('beforeunload', internalHandler, true); 
} else if (window.attachEvent) { 
    window.attachEvent('onbeforeunload', internalHandler); 
} 

如果你阻止用户将其关闭,以确认关闭事件任何你无法控制ALT + F4或从任务管理器关闭的方式

您可以使用JavaScript这样

var message = "You have not completed exam. Are you sure you want to leave?"; 
window.onbeforeunload = function(event) { 
var e = e || window.event; 
if (e) { 
    e.returnValue = message; 
} 
return message; 
}; 

它做,你可以卸载它,当用户完成考试

window.onbeforeunload = null; 

,或者你可以用C#Windows窗体创建自己的浏览器应用程序。您可以在此设置此自定义选项而无需关闭按钮。您可以轻松地在Windows窗体应用程序中加载Web应用程序表单

onbeforeunload & onunload将帮助你。您无法禁用,但可以向用户显示警报。

var showMsgTimer; 
window.onbeforeunload = function(evt) { 
    var message = 'Don't Discard'; 
    showMsgTimer = window.setTimeout(showMessage, 500); 
    evt = evt || window.evt; 
    evt.returnValue = message; 
    return message; 
} 

window.onunload = function() { 
    clearTimeout(showMsgTimer); 
} 

function showMessage() { 
    alert("You're Right!"); 
} 

如果这不是您所期望的。然后请尝试https://eureka.ykyuen.info/2011/02/22/jquery-javascript-capture-the-browser-or-tab-closed-event/