65.9K
CodeProject is changing. Read more.
Home

Prevent your site data from being copied

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.50/5 (2 votes)

Jul 28, 2011

CPOL
viewsIcon

14344

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.

<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>