![](/img/trans.png)
[英]Why would my HTML webpage refresh when i click a button that closes a form
[英]Logout webpage when click on refresh button
我正在开发一个网站。 当我尝试刷新页面时,我需要注销页面。
单击f5
进行刷新时,我获得了注销代码,并且还获得了禁用页面right click
的代码。 但我不知道如何在按下刷新按钮时阻止浏览器的刷新按钮或注销。 我搜索了很多网站。 但没有得到答复。
我为F5
键选择的代码是
function fkey(e){
e = e || window.event;
if( wasPressed ) return;
if (e.keyCode == 116) {
alert("f5 pressed");
wasPressed = true;
}else {
alert("Window closed");
}
}
任何人都可以帮助我解决刷新按钮的问题吗?
我认为它会起作用
$("*").keypress(function(e)
{
if (e.keyCode == 116) {
e.preventDefault();
}
});
尝试这个:
window.onbeforeunload = function(e){
//call logout process here
}
onbeforeunload 是在窗口即将卸载其资源时触发的事件。 该文档仍然可见并且该事件仍然可以取消,换句话说,每当您刷新或关闭页面时,它都会触发一个事件“onbeforeunload”。 当此事件返回非空值时,系统会提示用户确认页面卸载。 在大多数浏览器中,事件的返回值显示在此对话框中。
参考: https : //developer.mozilla.org/en-US/docs/WindowEventHandlers.onbeforeunload
window.onbeforeunload = function(e){
//call logout process here
}
OnBeforeUnload 上的任何自定义声明都不会执行,因为从代码中删除了支持。 因此,上述解决方案不适用于 Chrome。 相反,使用 HttpContext.GetOwinContext().Authentication.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.