Quick solutions to prevent the use of the tab key on webpages

Source: Internet
Author: User

In some web pages or in the pop-up layer, we generally do not want to use tab or

After the tab key is used, some problems may occur, such:

After the pop-up layer, the tab key can also be operated on the page, which leads to a script error.

So what if we want to avoid this situation?

Control by Keyboard Events
Copy codeThe Code is as follows:
<Script language = "javascript" type = "text/javascript" src = "../javascript/jquery-1.2.6.min.js"> </script>
<Script language = "javascript" type = "text/javascript">
$ (Document). ready (function (){
$ (Document). bind ('keylow', function (event ){
If (event. keyCode = 9 ){
Document. body. focus ();
}
});
});
</Script>

The above code is familiar with that when you press the tab key, move the focus to the top of the tabindex 0 again.

At this time, we need to set the page focus for initialization at the beginning of the page.

For example, the following example is written using aspx:

<Box: Button ID = "BtnClose" Text = "Close" runat = "server" SystemIcon = "Close" TabIndex = "0" FocusOnPageLoad = "true">
</Box: Button>

In some special cases, we need to set the focus position during page loading to prevent the tabindex setting from being invalid or affected by other factors.

In this way, we can be foolproof!

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.