如何从浏览器的菜单栏中禁用刷新按钮

时间:2017-12-25 12:24:02

标签: javascript jquery html angular

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

1 个答案:

答案 0 :(得分:5)

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>

相关问题