jquery Disable keyboard back shield F5 Refresh and disable right-click _jquery

Source: Internet
Author: User
Tags delete key tagname

This article describes the four ways in which jquery disables multiple functions

1, disable F5 refresh jquery instance Code
F5 has the ability to refresh Web pages, and may sometimes need to disable this feature, the following is a code example to explain how to implement this feature.
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 disable keyboard back, F5 refresh and other shortcut keys

$ (document). KeyDown (function (event) {
   
     //shielding ALT + Direction key ← 
     //Shielding ALT + Direction key →
     if (event.altkey) && ( event.keycode==37) | | (event.keycode==39)))  
     { 
        event.returnvalue=false; 
        return false;
     }
 
     Mask BACKSPACE Delete key 
     if (event.keycode==8) {return
        false; 
     }
        
     Mask F5 Refresh key 
     if (event.keycode==116) {return
        false; 
     }
 
    Shielded Alt+r 
    if ((Event.ctrlkey) && (event.keycode==82)) {return
       false; 
    }

 });

3. Disable 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 to prevent the BACKSPACE key page back to the implementation code

$ (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.disable D; 
} 
else 
doprevent = true; 
} 
else 
doprevent = false; 

if (doprevent) 
e.preventdefault (); 
}); 

The above is the entire content of this article, I hope 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.