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