Home > Web Front-end > JS Tutorial > body text

How to prevent page refresh with JavaScript

coldplay.xixi
Release: 2020-11-30 16:40:14
Original
8460 people have browsed it

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 () 】.

How to prevent page refresh with JavaScript

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;
    }
}
Copy after login

2. Disable right-click pop-up menu

document.oncontextmenu = function () {
    return false;
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template