Look at the code:
| The code is as follows |
Copy Code |
<body oncontextmenu= "alert (' ^_^ Don't peek Oh! '); return false > Right on top of me, look. </body>
|
Right-click on the top of the text, pop-up message box, as shown:
The same function, can be implemented in many ways, it depends on your personal practice, the above functions can also be achieved through the following code:
| The code is as follows |
Copy Code |
<script language= "JavaScript" > <!-- function Getbutton () { if (Event.button = = 2) { Alert ("^_^ Don't peek!" "); } } Document.onmousedown = Getbutton; --> </script> <body> Disable right mouse button </body> |
But sometimes, the right key of the input box is not blocked, then you can use the following script:
| The code is as follows |
Copy Code |
| if ( Document.layers) { document.captureevents (event.mousedown); } Document.onmousedown = click; Document.oncontextmenu = new Function ("return false;") Function Click (e) { e = e | | event; if (E.button = 2) { &NBSP;&N Bsp var tag = E.srcelement | | E.target; if (Tag.type = = "Text" | | | tag.type = "TEXTAREA") { document.oncontextmenu = new Function ("return true;") } else { document.oncontextmenu = new Function ("return false;") } &NBSP;} } |