Javascript disables the right-click function. JS disables the right-click function.

Source: Internet
Author: User

Javascript disables the right-click function. JS disables the right-click function.

When you want to save beautiful pictures or wonderful texts on a webpage, you usually select the target and right-click it, select "Save image as" or "copy" in the pop-up menu to achieve our goal. However, many web pages are currently blocked by right-clicking. How can I disable the right-clicking function in JavaScript?

1. JS instructions related to disabling right-click

<script type="text/javascript">document.oncontextmenu=new Function("event.returnValue=false;");document.onselectstart=new Function("event.returnValue=false;");</script>

2. Right-click prohibited Firefox failure

<! DOCTYPE html> 

3. Disable Text Selection

<script type="text/javascript">var omitformtags=["input", "textarea", "select"];omitformtagsomitformtags=omitformtags.join("|");function disableselect(e){if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1){return false;}}function reEnable(){return true;}if (typeof document.onselectstart!="undefined"){document.onselectstart=new Function ("return false");}else{document.onmousedown=disableselect;document.onmouseup=reEnable;}</script>

4. shield the ctrl button

document.onkeydown=function(){if(event.ctrlKey)return false;}

The above section describes how to disable right-clicking in JavaScript code. I hope it will be helpful to you. If you have any questions, please leave a message. The editor will reply to you in time, thank you very much for your support for the help House website!

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.