Oncontextmenu event (convert)

Source: Internet
Author: User

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 ()

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.