Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Firefox

Prevent your site data from being copied

4.50/5 (2 votes)
28 Jul 2011CPOL 14.3K  
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)