protect copy of data on page in javascript

Posted on May 15, 2008. Filed under: JavaScript |

<

SCRIPT language=javascript type=text/javascript> 

function disableCtrlKeyCombination(e)

{//list all CTRL + key combinations you want to disable 

var forbiddenKeys = new Array(‘a’, ‘n’, ‘c’, ‘x’, ‘v’, ‘j’);

var key;var isCtrl;

if(window.event)

{key = window.event.keyCode; //IE

if(window.event.ctrlKey)

isCtrl = true;

else

isCtrl = false;

}

else

{key = e.which; //firefox

if(e.ctrlKey)

isCtrl = true;

else

isCtrl = false;

}

//if ctrl is pressed check if other key is in forbidenKeys array

if(isCtrl)

{for(i=0; i<forbiddenKeys.length; i++)

{// alert(forbiddenKeys[i]);

//case-insensitive comparation

if(forbiddenKeys[i].toLowerCase() == String.fromCharCode(key).toLowerCase())

{// alert(’Key combination CTRL + ‘ +String.fromCharCode(key) +’ has been disabled.’);

return false;

}}}

return true;

function click(e) {

if (document.all) {

if (event.button == 2) {

//alert(message);

return false;

}}

if (document.layers) {

if (e.which == 3) {

// alert(message);

return false;

}}}

if (document.layers) {

document.captureEvents(Event.MOUSEDOWN);

}

document.onmousedown=click;

</script>

in body tag write

<body oncontextmenu=”return false” onkeypress

=”return disableCtrlKeyCombination(event);” onkeydown=”return disableCtrlKeyCombination(event);” >

Make a Comment

Make A Comment: ( None so far )

blockquote and a tags work here.

    About

    Hi,I am Suresh Sharma(MCP) from Gorakhpur , UP, India.I have work on .net technology from 2 years. Key skills-Asp.net 2.0,3.5, Sql 2005,2000. Ajax.net 1.1,C#.net

    RSS

    Subscribe Via RSS

    • Subscribe with Bloglines
    • Add your feed to Newsburst from CNET News.com
    • Subscribe in Google Reader
    • Add to My Yahoo!
    • Subscribe in NewsGator Online
    • The latest comments to all posts in RSS
    • Subscribe in Rojo

    Meta

Liked it here?
Why not try sites on the blogroll...