Example code for JavaScript to prevent page operations

Source: Internet
Author: User
Tags mail

  This article is about JavaScript to prevent page operation of the sample code is introduced, the need for friends can come to the reference, I hope to help you.

Single JS ban page right menu-Avoid website information stolen   code as follows: <script type= "Text/javascript" >   function block (oevent) {    if (window.event)     oevent=window.event;    if (oevent.button==2)     alert ("right mouse button not available");  }   Document.onmousedown=block; </script>   Web pages prohibit replication primarily by JavaScript.   <body oncontextmenu= ' return false ' onselectstart= ' return false '   ondragstart= ' return false ' Onbeforecopy= "return False" Oncopy=document.selection.empty () onselect=document.selection.empty () > ------ -----------------------------------------to prevent copying the JS-----------------------------------------------code as follows: <script language=javascript1.2> function Disableselect (e) {return false} function reenable () {return true} file://if ie4+ docu Ment.onselectstart=new Function ("return false") file://if NS6 if (window.sidebar) {Document.onmousedown=disableselect document.onclick=reenable} </SCRIPT> <script language=javascript type=text/javascript> <!--function mm_reloadpage (init) {   //reloads the window if Nav4 resized     if (init==true With (navigator) {if (appname== "Netscape") && (parseint (appversion) ==4)) {      document. Mm_pgw=innerwidth; Document. Mm_pgh=innerheight; Onresize=mm_reloadpage; }     Else if (innerwidth!=document. MM_PGW | | Innerheight!=document. MM_PGH) location.reload (); } mm_reloadpage (True); --> </SCRIPT>  -------------------------------------------------------to prevent the download of JS------------------- ------------------------------------<noscript><iframe src= "" ></iframe></noscript>------ --------------------------------------------------  Below is to prevent the right key of JS:   code as follows: <script language= "JavaScript" >   <!--if (window. Event)   document.captureevents (event.mouseup);  function Nocontextmenu () {event.cancelbubble = True Event.returnvalue = false; return false; } function Norightclick (e) {if (window. Event) {   if (E.which = = 2 | | e.which = = 3)    return false;} else{   if (Event.button = 2 | | event.button = = 3) {       event.cancelbubble = True &nbsp ;   Event.returnvalue = false;        return false;    }}   Document.oncontextmenu = Nocontextmenu; For ie5+ document.onmousedown = Norightclick; For all others//--> </script>   <TITLE>CSS prohibit selection and replication </title> <meta http-equiv= " Content-type "content=" text/html;charset=gb2312 "> <style> body{ -moz-user-select:none;  hutia: Expression (This.onselectstart=function () {return (FALSE)}); } </style> </head> <body> Here is the content of the Web page, try you can copy? </body> </html>     Application example: Code as follows: <html xmlns= "http://www.w3.org/1999/xhtml" > <head runat= "Server" >     <TITLE>JS control page </title>     <script language= "javascript" type= "text /javascript "> &nbsp      //prohibit users from using mail (hide right menu)         Document.oncontextmenu = function Forbidrightkey () {& nbsp           Window.event.returnValue = false;         &NBSP,          //prohibit users from using mail (prompt user to disable right button)         &NB Sp;function block () {             var oevent;           &NBSP ;  if (window.event)                  oevent = window.event;              if (Oevent.button = 2)               & nbsp  alert ("right mouse button not available");          }          document.onmousedown = block;          //When the user presses ALTF4, prompts to close the window information         function altF4 () {    & nbsp       if (Window.event.altKey && windowEvent.keycode = = +) {                  Window.close ()     &NBS P      }         {       //alt the left mouse button to make a shortcut key select how to call content in a text box <body on Keydown= "altF4 ();" >         function Gettxtselect (Eventcontrol) {        &NBS P   if (Eventcontrol.altkey) {                document.getElementById ("Txt1"). Select ();                     {          function Clea Rtxtbyinput () {            document.getElementById ("Txtcontent"). Value = "";        }           function filltxtbyinput () {        & nbsp   document.getElementById ("Txtcontent"). Value = "Input search condition";        }        //Disable a few keys on the keyboard call onKeydown= "Forbidkeys ();"         function Forbidkeys () {            var Content = Window.event.keyCode;             if (content >= && content <=) {                Window.event.returnValue = false;            } else {                Window.alert Co Ntent);                     {         //Prohibit copying Web content &L T;body oncopy= "forbidcopy ();" >          function forbidcopy () {            Window.event.retu Rnvalue = false;             Window.clipboardData.setData ("Text", "");             alert ("Prohibit copying Web content!") ");        }          //Set copy content attach URL of this site   &NBSP     Function setcopycontent () {            Window.event.returnValue = false; &nbs P           var content = Document.title + "/r/n";             content + + document.getElementById ("Txt1"). Value + "/r/n";             content = "This resource comes from" + this.location.href;             window.clipboardData.setData (' Text ', content);             alert ("Copy successful, paste on your qq/msn to recommend to your friends");        }          //disable refreshing F5 and ctrl+f5         function Fo Rbidfreshpage () {              if (Window.event.ctrlKey && window.event.keyCo De = = 116) | | Window.event.keyCode = = 116) {               window.event.keycode = 0;   &NB Sp            WINDOW.EVENT.RETURNVALue = false;            }          {        Document.onkeyd own = Forbidfreshpage;        //Masking JS error         function killerrors () {      &nbsp   ;   return true;        }         window.onerror = killerrors;                </script> </head> <body>     <form I D= "Form1" runat= "Server" >     <div>         <input id= "txt1" type= "text" value= " Hello world! " onclick=" Gettxtselect (event) "/>         <input type=" button "value=" Copy the value in the text box " onclick=" setcopycontent (); "/>         <input id=" txtcontent "value=" Enter search criteria " Style= "Color:aqua" onclick= "cleartxtbyinput ();"  onblur= "filltxtbyinput ();"/>         <p>content</p>       </div>     </form> </body> </html>  
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.