【问题标题】:How to disable refresh button from browser's menu bar如何从浏览器的菜单栏中禁用刷新按钮
【发布时间】:2018-06-06 16:56:06
【问题描述】:

如何使用 angularjs 或 javascript 或 jquery 禁用浏览器菜单栏中的刷新按钮

【问题讨论】:

  • 你为什么要这样做?
  • 请改用angularjs标签。
  • 为什么要这个操作,因为我正在开发一个在线考试的应用程序。所以刷新选项不应该对学生可见

标签: javascript jquery html angular


【解决方案1】:

function disableF5(e) { if ((e.which || e.keyCode) == 116) e.preventDefault(); };
$(document).on("keydown", disableF5);

// simply visual, let's you know when the correct iframe is selected
$(window).on("focus", function(e) {
    $("html, body").css({ background: "#FFF", color: "#000" })
    .find("h2").html("THIS BOX NOW HAS FOCUS<br />F5 should not work.");
})
.on("blur", function(e) {
    $("html, body").css({ background: "", color: "" })
    .find("h2").html("CLICK HERE TO GIVE THIS BOX FOCUS BEFORE PRESSING F5");
});
html, body { background: #000; color: #FFF; height: 100%; margin: 0; padding: 0; width: 100%; }
div { display: table; height: 100%; width: 100%; }
h2 { display: table-cell; text-align: center; vertical-align: middle; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
    <h2>CLICK HERE TO GIVE THIS BOX FOCUS BEFORE PRESSING F5</h2>
</div>

【讨论】:

  • 此代码仅在焦点位于框内时有效。您不能禁用浏览器刷新按钮。
猜你喜欢
  • 2011-07-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多