Implementation principle of javascript custom right-click and source code _ javascript skills

Source: Internet
Author: User
This article mainly introduces the implementation principle and source code of JavaScript custom right-click. If you need it, you can record the Javascript custom right-click by referring to the following example, let's first break down its implementation principles:

1. Block default events by right-click (I thought the modified event was the default event)

2. Hiding a ul; (this is what I once think is worth doing so is p, Khan)

3. Right-click the response to show the hidden ul;

4. After clicking the mouse again, ul is hidden again.

In this case, the things we need to do are much simpler. First, we should go to the Code:

Html section

 
 
  • Start
  • Pause
  • Bye bye

Javascript section:

Window. onload = function () {var forRight = document. getElementById ("testRight"); // get the object. Now you are too familiar with forRight. style. display = "none"; var title = forRight. getElementsByTagName ("li"); for (var I = 0; I
 
  


Let's take a look at the most important part of today's record: document. if the oncontextmenu event returns false, the default event is blocked. If we do not write any other event, we only write return in this event, as shown below:

document.oncontextmenu=function(){ return false; }

In this case, right-clicking will not cause any response. Then, let's look at the entire event application. It seems that all the other events except this event are familiar, but there is always a lack of integration of the event. The key is the idea, however, no matter where it is, set it up first, but please read three thousand first, not just ask for help. Zamazoo, zamazoo, and zamazoo .....

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.