Click here to Skip to main content
15,887,328 members
Articles / Firefox
Tip/Trick

Prevent your site data from being copied

Rate me:
Please Sign up or sign in to vote.
4.50/5 (2 votes)
28 Jul 2011CPOL 13.6K   4   4
Disabling Ctrl+c and other commands in your browser.

This program will help you in diabling operations like copying in your website.


Note: It is not a very secure method and can be broken easily.


The program I am posting only covers Firefox but a little change in the program will make it work on Internet Explorer as well.


In the code below, e.which determines the keycode, that is the key you pressed. 99, 118 etc., are the ASCII codes. This trick disables Ctrl+c, Ctrl+v, and Ctrl+n.


XML
<html>
<head>
<script type="text/javascript">

function findKeyboardEvents(e) {
    // get key code
    var key_code = (window.event) ? event.keyCode : e.which;

    if (e.ctrlKey && (key_code==99 || key_code==118 || key_code==110 || 
                        key_code==67 || key_code==86 || key_code==78)) {
        alert("Sorry this operation is not allowed");
        e.preventDefault();
    }
}

window.document.onkeypress = findKeyboardEvents;
</script>
</head>
<body>
csanuragjain
</body>
</html>

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
India India
I am a Java software developer. I like to make new software which can be helpful to people. You may get in touch with me at https://cooltrickshome.blogspot.in

Comments and Discussions

 
GeneralAnd then I just select View Source from the menu and I can c... Pin
o m n i1-Aug-11 8:32
o m n i1-Aug-11 8:32 
GeneralRe: Absolutely correct, but it stops casual copying. An example ... Pin
HueyHQ2-Aug-11 10:04
HueyHQ2-Aug-11 10:04 
GeneralWill it also control mouse right click in Firefox to select ... Pin
Mehul M Thakkar29-Jul-11 2:42
Mehul M Thakkar29-Jul-11 2:42 
GeneralRe: No this one only disables ctrl+c For mouse operation you nee... Pin
csanuragjain29-Jul-11 3:41
csanuragjain29-Jul-11 3:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.