Web Analytics Made Easy -
StatCounter avoid ctrl c and ctrl v operation - CodingForum

Announcement

Collapse
No announcement yet.

avoid ctrl c and ctrl v operation

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • avoid ctrl c and ctrl v operation

    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

  • #2
    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>
    Glenn
    vBulletin Mods That Rock!

    Comment


    • #3
      ... I'm just curious.... what is the purpose of a script like that.....
      Vladdy | KL
      "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

      Comment

      Working...
      X