如何阻止用户使用javascript或jquery在Mozilla Firefox 24中按 F5 和 CTRL + R 。
答案 0 :(得分:0)
您无法阻止用户重新加载您的网页,但您可以在离开或重新加载之前显示消息:
window.onbeforeunload = function(e) {
return 'Do You really want to leave the page?';
};
您还可以为Ctrl或F5按键设置事件处理程序,并防止发生默认值,但出于安全考虑,它在大多数浏览器中不适用于功能键(如Ctrl或F键)。
答案 1 :(得分:0)
<script language="javascript" type="text/javascript">
//this code handles the F5/Ctrl+F5/Ctrl+R
document.onkeydown = checkKeycode
function checkKeycode(e) {
var keycode;
if (window.event)
keycode = window.event.keyCode;
else if (e)
keycode = e.which;
// Mozilla firefox
if ($.browser.mozilla) {
if (keycode == 116 ||(e.ctrlKey && keycode == 82)) {
if (e.preventDefault)
{
e.preventDefault();
e.stopPropagation();
}
}
}
// IE
else if ($.browser.msie) {
if (keycode == 116 || (window.event.ctrlKey && keycode == 82)) {
window.event.returnValue = false;
window.event.keyCode = 0;
window.status = "Refresh is disabled";
}
}
}
</script>