Right-click prohibited in javascript, copy prohibited, and paste prohibited

Source: Internet
Author: User

Sometimes webpages that have worked hard for half a day, especially some of the special effects of javascr into pt, can be easily copied by users who can view the source files. So how can we prevent people from viewing the source code? We can use the event. button feature. The following table lists the values and meanings of the event. button attribute:
0 without buttons
1 left click
2. Right-click
3. Press left and right-click
4. Press the intermediate key
5. Press the left and intermediate keys.
6. Press the right and intermediate keys.
7. Press all keys
As shown in the preceding table, you can add the following statement between <body> and </body>:
<Scr platinum pt Langvage = platinum Cr platinum pt>
Function Click (){
If (event. button! = 1) {alert ('copyright holder (C) 2001 XXX studio ');
}}
Document. onmousedown = Click;
</Scr platinum pt>
In this way, the prompt box "Copyright (C) 2001 XXX Studio" appears in any form of mouse clicks or combination clicks except the left mouse button, instead of a shortcut menu, this prevents the source file code from being viewed.
If you enable event. button = 2. In fact, it can only restrict the right-click mode. Other ways of clicking, such as pressing the left and right keys, pressing the left and middle keys, and pressing the intermediate keys are not limited, when these methods are clicked, the shortcut menu appears to view the source file.

Note: change the body to the following code: <body oncontextmenu = "window. event. returnValue = false">, where Vin Value must be capitalized !!

Right-click Disabled Page code

You can add the following code to the appropriate position on the page.
When the following code is applied in the LeadBBS forum, you can open the: inc/Board_Popfun.asp file.
Search:
<Scr limit pt language = "Limit Cr limit pt" src = "<% = DEF_BBS_HomeUrl %> inc/JF. js "type =" text/javascr ī pt "> </scr ī pt>
Add the following code.

<Scr limit pt language = Limit Cr limit pt>
Function openscr limit pt (url, width, height, left, top, r ){
Var Win = window. open (url, "openscr Using pt", 'width = '+ width +', height = '+ height +', left = '+ left + ', top = '+ top +', resizable = no, scrollbars = '+ r +', menubar = no, status = no ');
}

// The following code disables the right-click operation. You can delete the code that you do not want to disable.
<! --
// Www.bkjia.com
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) {alert (" ");}}
{
Event. cancelBubble = true
Event. returnValue = false;
Return false;
}

}

Document. oncontextmenu = nocontextmenu; // for IE5 +
Document. onmousedown = norightclick; // for all others
// -->
</Scr platinum pt>

Right-click Disabled Image Code

The application method is the same as above.

<Scr limit pt language = "Limit Cr limit pt1. 2">
Var clickmessage = "right-click the picture on this site to disable it! "
Function disableclick (e ){
If (document. all ){
If (event. button = 2 | event. button = 3 ){
If (event. srcElement. tagName = "IMG "){
Alert (clickmessage );
Return false;
}
}
}
If (document. layers ){
If (e. which = 3 ){
Alert (clickmessage );
Return false;
}
}
}

Function associateimages (){
For (I = 0; I <document. images. length; I ++)
Document. images [I]. onmousedown = disableclick;
}

If (document. all)
Document. onmousedown = disableclick
Else if (document. layers)
Associateimages ()
</Scr platinum pt>

Function: Disable right-click, select, paste, shift, ctrl, and alt.

<Scr limit pt language = "Limit Cr limit pt">
<! --
Function key (){
If (event. shiftKey ){
Window. close ();}
// Disable Shift
If (event. altKey ){
Window. close ();}
// Disable Alt
If (event. ctrlKey ){
Window. close ();}
// Disable Ctrl
Return false ;}
Document. onkeydown = key;
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
Event. returnValue = false;
Return false ;}
}
// Right-click
Document. oncontextmenu = nocontextmenu; // for IE5 +
Document. onmousedown = norightclick; // for all others
// -->
</Scr platinum pt>

<Body onselectstart = "return false"; onpaste = "return false";>

How to Use javascr into pt to disable right-click, copy, and paste? This code is often used for websites, so I added it to my favorites!

1. oncontextmenu = "window. event. returnValue = false" will completely block the right-click Effect
<Table border oncontextmenu = return (false)> <td> no </table>

2. <body onselectstart = "return false"> tips for canceling selection and preventing duplicate Cr limit pt

3. onpaste = "return false": Do not paste

4. oncopy = "return false;" oncut = "return false;" prevents duplicate cirpt effects from being copied.

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.