简体   繁体   English

在Internet Explorer 9中禁用F5

[英]Disable F5 in internet Explorer 9

I have a JS Application that runs some kind of things. 我有一个运行某种东西的JS应用程序。

I want to disable ctrl + r and f5 so I don't get a browser refresh. 我想禁用ctrl + rf5,所以我没有刷新浏览器。

I disable ctrl + r completely and replace the disabled f5 refresh with my own handling (ajax, calls on RAP,DB, etc.) 我完全禁用ctrl + r,并用自己的处理方式(ajax,对RAP,DB的调用等)替换禁用的f5刷新。

Both mechanics work fine on FF, Chrome, Opera and Safari. 两种机制都能在FF,Chrome,Opera和Safari上正常工作。
Which means I can spam-bot key combinations and everything works perfect. 这意味着我可以使用垃圾邮件自动组合键,一切正常。

In IE 9 though, when I press f5 to fast sequentially it does do a regular refresh, which means to me IE 9 takes to long for the operation and its no ready for the next keydown function. 但是,在IE 9中,当我按f5键快速顺序执行时,它会进行定期刷新,这对我来说意味着IE 9会花费很长时间进行操作,而它不准备进行下一个按键功能。

$(document).keydown(function (event) {
    if ((event.ctrlKey == true && (event.keyCode == 17 || event.keyCode == 82)) || (event.keyCode == 116)) {
        event.preventDefault();
        if (event.keyCode == 116) {
            // Here is the own Reload Logic which contains calls on DB and Server.              
        }
        if ($.browser.msie) {
            window.event.stopPropagation();
            window.event.keyCode = 0;
            window.event.returnValue = false;
            window.event.cancelBubble = true;
        }
    }
});

Is it possible to somehow manage this to fast pressing f5 (so it keeps being disabled) in IE 9? 是否可以通过某种方式对此进行管理以在IE 9中快速按f5键 (使其一直处于禁用状态)?

You can only prevent F5 with WebBrowserShortcutsEnabled, but you will kill all other shortcuts the browser has on that page. 您只能使用WebBrowserShortcutsEnabled阻止F5,但是您将杀死该页面上浏览器具有的所有其他快捷方式。 You should try to block the process of people leaving the webpage. 您应该尝试阻止人们离开网页的过程。 That would be more productive in what you want to achieve. 这将在您想要实现的目标中提高生产力。

window.onbeforeunload = function() {
    return "You are trying to leave.";
}

This should not be used as a safety measure tho, like for students taking web-tests/exams. 请勿将其用作安全措施,例如对于参加网络测试/考试的学生。 But if it's just to prevent accidental refresh, this should do the trick. 但是,如果只是为了防止意外刷新,则应该这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM