Enable right-click menu with oncontextmenu event ticket
In a page, the oncontextmenu = 'Return false' is used in the body to cancel the right-click operation. In JS, set oncontextmenu = 'Return true' to use response handler Doc ument. oncontextmenu = function () {return false ;}
Oncontextmenu = Window. event. returnvalue = false; Right-click the menu to Disable copying.
Add the property code to <body>:
Oncontextmenu = "Return false"
Onselectstart = "Return false" Disable content on the selected webpage
Oncopy = "Return false" prevents copying content selected by the user on the webpage
Prevent users from saving web pages:
The <NoScript> <IFRAME src = *. html> </iframe> </NoScript> label can prevent direct saving of webpages, but cannot prevent users from downloading webpages using tools.
* Is a wildcard.
Example 1:
<HTML>
<Head>
<Title> oncontextmenu event </title>
<Script language = "JavaScript">
<! --
Function ufunction ()
{Document. All. infodiv. innerhtml = 'Right-click, but the right-click menu cannot be displayed! ';}
Function ufunction2 ()
{Document. All. infodiv. innerhtml = 'You press Ctrl + Right-click to display the right-click menu. ';}
// -->
</SCRIPT>
</Head>
<Body oncontextmenu = "If (! Event. ctrlkey) {ufunction (); Return false} else {ufunction2 ()} ">
<Div id = "infodiv"> right-click, but the right-click menu cannot be displayed! <Br> you press Ctrl + Right-click to display the right-click menu.
</Div> </body>
</Html>
Oncontextmenu event ()