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
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 .....