我正在一个项目中,不允许用户使用以下任何技术刷新页面:
刷新, F5, CTRL+ F5, CTRL+ r... 等。
document.addEventListener('DOMContentLoaded', function (e) {
document.body.addEventListener('keydown', function (e) {
if (e.keyCode == 116) {
e.preventDefault();
}
}, false);
}, false);
它几乎不可能做这样的事情,你可以提示用户刷新,
var confirmOnPageExit = function (e) {
// If we haven't been passed the event get the window.event
e = e || window.event;
var message = 'Any text will block the navigation and display a prompt';
// For IE6-8 and Firefox prior to version 4
if (e) {
e.returnValue = message;
}
// For Chrome, Safari, IE8+ and Opera 12+
return message;
};
window.onbeforeunload = confirmOnPageExit;