JQuery disables keyboard unblocking F5 refresh and disable right-click _ jquery

Source: Internet
Author: User
Tags rewind
This article mainly introduces jQuery shortcut methods such as disabling keyboard rewind, shielding F5 refresh, and disabling right-click, if you are interested, refer to the examples in this article to introduce 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.