JS related Forbidden

Source: Internet
Author: User

When you encounter a beautiful picture on a webpage or if you want to save a wonderful text, you usually select the target and press the right mouse button, select "Save Picture as" or "copy" in the pop-up menu to achieve our goal. However, at present, there are many Web pages are blocked the right mouse button, then use JS how to implement the function of prohibiting the right mouse button?

1. JS instructions related to the Forbidden right mouse button

1 <Scripttype= "Text/javascript">2 Document.oncontextmenu=NewFunction ("Event.returnvalue=false;");3 Document.onselectstart=NewFunction ("Event.returnvalue=false;");4 </Script>

2. Disable right mouse button Firefox malfunction

<!DOCTYPE HTML><HTML><Head>    <title>Disable right mouse button</title>    <MetaCharSet= "Utf-8"></Head><Body>    <Divclass= "Poo">This page cannot use the right mouse button</Div>    <!--Disable right mouse button -    <Scripttype= "Text/javascript">        if(window.           Event) {document.captureevents (event.mouseup); }        functionNocontextmenu () {event.cancelbubble= trueEvent.returnvalue= false; return false; }                    functionNorightclick (e) {if(window. Event) {if(E.which== 2 ||E.which== 3)                  return false; } Else  if(Event.button== 2 ||Event.button== 3) {event.cancelbubble= trueEvent.returnvalue= false; return false; }} Document.oncontextmenu=Nocontextmenu;//For ie5+Document.onmousedown=Norightclick;//For all others    </Script>  </Body></HTML>

3. Disable text selection

<Scripttype= "Text/javascript">    varOmitformtags=["input", "textarea", "Select"]; Omitformtagsomitformtags=Omitformtags.join ("|"); functionDisableselect (e) {if(Omitformtags.indexof (E.target.tagname.tolowercase ())==-1){            return false; }    }    functionreenable () {return true; }    if (typeofDocument.onselectstart!="undefined") {Document.onselectstart=NewFunction ("return False"); }Else{Document.onmousedown=Disableselect; Document.onmouseup=reenable; }</Script>

4. block the CTRL key

Document.onkeydown=function () {if (Event.ctrlkey) return false;}

JS related Forbidden

Related Article

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.