...

View Full Version : avoid ctrl c and ctrl v operation



rama
07-09-2002, 03:16 AM
Hi,

I want to prevent the user from copying text and pasting it in text area or a textbox.I have disabled the right clicks etc.

But if the user uses ctrl c and ctrl v,i am not able to detect.

Is there any way to check this key combination,ie if the user uses ctrl key and the alphabet "C" and similarly ctrl key and V then i want to restrict him.


Is it possible to check for the key combinations and disable the operation.How can i do this using javascript.


Thanks

Rama

glenngv
07-09-2002, 03:56 AM
you can disable ctrl+v and ctrl+c in IE but I think in NS you cannot prevent it though you can detect it. So to work with NS, you need to alert a msg once CTRL key is pressed.


javascript:

function noCTRL(e)
{
var code = (document.all) ? event.keyCode:e.which;
var ctrl = (document.all) ? event.ctrlKey:e.modifiers & Event.CONTROL_MASK;
var msg = "Sorry, this functionality is disabled.";
if (document.all)
{
if (ctrl && code==86) //CTRL+V
{
alert(msg);
window.event.returnValue = false;
}
else if (ctrl && code==67) //CTRL+C (Copy)
{
alert(msg);
window.event.returnValue = false;
}
}
else {
if (ctrl==2) //CTRL key
{
alert(msg);
return false;
}
}
}



html:

<texarea onkeydown="return noCTRL(event)"></texarea>

Vladdy
07-09-2002, 06:09 AM
... I'm just curious.... what is the purpose of a script like that.....:confused: :confused:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum