Js shield direction keys, compatible with IE and firefox

Source: Internet
Author: User

I would like to share with you how to use js to shield users from pressing the direction keys (compatible with IE and firefox )! Add the following code to the head and body areas of the source code.

Document. onkeydown = function (e) {e = e | event; // mask the left direction key if (e. keyCode = 37) {alert ('Do not move to the left direction key! '); Return false;} // specifies the direction key for blocking the upward direction. if (e. keyCode = 38) {alert ('prohibit the direction key for upward direction! '); Return false;} // mask the right direction key if (e. keyCode = 39) {alert ('prohibit the right direction key! '); Return false;} // mask the downward direction key if (e. keyCode = 40) {alert ('prohibit downward direction keys! '); Return false ;}}
Articles you may be interested in
  • Js shields mouse and keyboard events (including right-click, direction key, backspace key, F5 refresh key, etc.), compatible with IE and firefox
  • Javascript shield right-click, compatible with IE and firefox
  • Javascript determines whether the mouse is left or right-click-compatible with ie, firefox, chrome, and other major browsers
  • Js obtains the height of the scroll bar from the top and bottom of the browser. It is compatible with ie and firefox.
  • Js can only enter numbers and numbers with decimal points, compatible with IE and firefox
  • Javascript to get the current mouse position (compatible with IE and firefox)
  • Js to get the current mouse position, compatible with ie and firefox
  • Js obtains the number of rows and columns of a table (compatible with IE and firefox)

Related Article

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.