Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2002
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 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
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,950
    Thanks
    0
    Thanked 236 Times in 233 Posts
    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>

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ... 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"


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •