JQuery disables keyboard back shield F5 refresh and disable right-click, jqueryf5
This document introduces four methods for jquery to disable multiple functions.
1. Disable F5 to refresh jQuery instance code
F5 has the ability to refresh the web page, and may sometimes need to disable this function. The following describes how to implement this function through code instances.
The Code is as follows:
$(document).ready(function(){ $(document).bind("keydown",function(e){ var e=window.event||e; if(e.keyCode==116){ e.keyCode = 0; return false; } }) })
2. jQuery disables shortcut keys such as keyboard rewind and F5 refresh
$ (Document ). keydown (function (event) {// mask Alt + direction key ↓ // mask Alt + direction key → if (event. altKey) & (event. keyCode = 37) | (event. keyCode = 39) {event. returnValue = false; return false;} // block the unsigned deletion key if (event. keyCode = 8) {return false;} // block the F5 refresh key if (event. keyCode = 116) {return false;} // block alt + R if (event. ctrlKey) & (event. keyCode = 82) {return false ;}});
3. Disable the right-click Function
The Code is as follows:
$(document).ready(function() { $(document).bind("contextmenu",function(e) { alert("sorry! No right-clicking!"); return false; }); });
4. jQuery's implementation code to prevent page bounce
$(document).keydown(function (e) { var doPrevent; if (e.keyCode == 8) { var d = e.srcElement || e.target; if (d.tagName.toUpperCase() == 'INPUT' || d.tagName.toUpperCase() == 'TEXTAREA') { doPrevent = d.readOnly || d.disabled; } else doPrevent = true; } else doPrevent = false; if (doPrevent) e.preventDefault(); });
The above is all the content of this article, hoping to help you learn.
Articles you may be interested in:
- Code for enabling and disabling server verification controls based on jquery
- Jquery displays and hides elements or is set to read-only (controls with Ligerui are disabled. instance description)
- Code forbidden by jquery batch control form
- Jquery-based code for disabling right-click, Text Selection, and copying keys
- Disable jquery right-click feature to block F5 refresh
- Example of jquery disabling right-click
- In-depth exploration of JavaScript and JQuery web page shielding right-click menu and prohibit select copy
- Jquery's attr method disables form elements to disable input content
- JQuery simply disables the right-click menu