Disable Web page Right-click menu and Mouse Drag selection

Source: Internet
Author: User
Tags tag name

First, prohibit the right mouse button menu: There are two ways to suppress the right mouse button 1, the HTML element in the body tag to add JavaScript event handle, the code is as follows:
<oncontextmenu= "return false">

Note: You can also disable the right button in the location specified in the webpage, for example, you just want to disable the right-click on a picture on a webpage, or you just want to disable the right-click on a text or table in a webpage, and you just add the red code as above to the corresponding HTML tag element, for example:
<imgsrc= "Logo.gif"width=88Height=31OnContextMenu= "return false"><!--add it to the picture. - <TableOnContextMenu= "return false"><!--Add to Table - <FontOnContextMenu= "return false">Text content</Font><!--add to the text -

2, write a JavaScript function, and then invoke the event processing, the code is as follows:
<Scriptlanguage=javascript><!--Document.oncontextmenu=Mylock1;functionMylock1 () {Event.returnvalue=false;}// -</Script>

Description: Please note that the code is case-sensitive! Copy the above code to the Web page HTML source code
<onselectstart= "return false">

Description: Similar to the above prohibited right-click Usage 2, write a JavaScript function, and then invoke event handling, the code is as follows:
<Scriptlanguage=javascript><!--Document.onselectstart=Mylock1;functionMylock1 () {Event.returnvalue=false;}// -</Script>

Description: Please note the case of the statement! Copy the above code to the Web page HTML source code
<oncontextmenu= "return false;" onselectstart = "return false" >

Method Two:
<Scriptlanguage=javascript><!--Document.onselectstart=Mylock1;document.oncontextmenu=Mylock1;functionMylock1 () {Event.returnvalue=false;}// -</Script>

Disable Web page Right-click menu and Mouse Drag selection

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.