Disable pop-up code of right-click menu of IE browser

Source: Internet
Author: User

Next, I will introduce you to a simple implementation method of disabling pop-up by right-clicking the IE browser menu. For more information, see.

Add the oncontextmenu event to the tag. To prevent event propagation and prevent the system from right-clicking the menu. So I did this:

The Code is as follows: Copy code

Var e = evt | window. event;

If (e. preventDefault ){
E. preventDefault ();
}

If (e. stopPropagation ){
E. stopPropagation ();
} Else {
E. cancelBubble = true;
}

It's okay in IE9, IE10, FireFox, and Chrome.

However, in IE8, right-click the system and the custom menu and System menu are displayed.


After searching for relevant information, you need to add a statement to prevent the context menu pop-up in IE8 and IE7:

The Code is as follows: Copy code

E. returnValue = false;

After the modification, my code is as follows:

The Code is as follows: Copy code

Var e = evt | window. event;

If (e. preventDefault ){
E. preventDefault ();
}

If (e. stopPropagation ){
E. stopPropagation ();
} Else {
E. returnValue = false; // right-click IE8 to pop up
E. cancelBubble = true;
}

Solve the problem. In fact, e. returnValue can prevent the pop-up of the right-click system menu of IE browsers.

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.