Home > Article > Web Front-end > How to prevent page refresh with JavaScript
How to disable page refresh in JavaScript: 1. Disable F5 refresh, the code is [if (event.keyCode == 116)]; 2. Disable the right-click pop-up menu, the code is [document.oncontextmenu = function () 】.
The operating environment of this tutorial: windows10 system, javascript1.8.5, this article is applicable to all brands of computers.
How to disable page refresh in JavaScript:
The JavaScript code to disable page refresh is as follows:
1. Disable F5 refresh
document.onkeydown = function () { if (event.keyCode == 116) { event.keyCode = 0; event.cancelBubble = true; return false; } }
2. Disable right-click pop-up menu
document.oncontextmenu = function () { return false; }
Related free learning recommendations: JavaScript (video)
The above is the detailed content of How to prevent page refresh with JavaScript. For more information, please follow other related articles on the PHP Chinese website!