Disable Paste and Drag event

Discussion in 'Javascript' started by khng, Apr 28, 2006.

  1. khng

    khng Guest

    How to disable the copy/drag event for some selected textfield as I
    want the user to key in instead of copy or drag the required
    information.

    For IE, I done it with the onPaste and onDragEnter Event, but it don't
    work on Other Browser, so I need your helping hand
     
    khng, Apr 28, 2006
    #1
    1. Advertising

  2. khng

    Touffy Guest

    On 2006-04-28 03:39:03 +0200, "khng" <> said:

    > How to disable the copy/drag event for some selected textfield as I
    > want the user to key in instead of copy or drag the required
    > information.


    You can't disable copy/paste. So you'll have to implement that another way.

    You can do it by watching keypress and onchange events.

    If the value of your input element changes without enough keys having
    been pressed, you'll know some characters weren't typed. For example,
    with an onkeypress event handler, you could increment a counter
    (decrement it for delete key, don't change for arrow keys, etc). Inside
    an onchange handler, compare that counter with how many characters were
    added to the value since the last onchange. If the number seems
    reasonable (don't be too strict though, if only 5 keys were pressed to
    input a 7-char-long string, maybe some events were just skipped or
    something...), then these chars were probably typed in the hard way.

    This rough method will also block auto-completing forms, and maybe some
    voice recognition software as well.

    I'm curious, why do you want your users to forsake the wondrous
    facilities offered by their OS and endanger their precious wrists ?


    --
    David Junger
     
    Touffy, Apr 30, 2006
    #2
    1. Advertising

  3. khng

    khng Guest

    Touffy wrote:
    > On 2006-04-28 03:39:03 +0200, "khng" <> said:
    >
    > > How to disable the copy/drag event for some selected textfield as I
    > > want the user to key in instead of copy or drag the required
    > > information.

    >
    > You can't disable copy/paste. So you'll have to implement that another way.
    >
    > You can do it by watching keypress and onchange events.
    >
    > If the value of your input element changes without enough keys having
    > been pressed, you'll know some characters weren't typed. For example,
    > with an onkeypress event handler, you could increment a counter
    > (decrement it for delete key, don't change for arrow keys, etc). Inside
    > an onchange handler, compare that counter with how many characters were
    > added to the value since the last onchange. If the number seems
    > reasonable (don't be too strict though, if only 5 keys were pressed to
    > input a 7-char-long string, maybe some events were just skipped or
    > something...), then these chars were probably typed in the hard way.
    >
    > This rough method will also block auto-completing forms, and maybe some
    > voice recognition software as well.
    >
    > I'm curious, why do you want your users to forsake the wondrous
    > facilities offered by their OS and endanger their precious wrists ?
    >
    >
    > --
    > David Junger


    Thanks you your suggestion...

    But for some field, e.g.the email field I want the user to type it
    manually instead of copy or drag
     
    khng, May 2, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest

    disable copy paste

    Guest, Dec 14, 2003, in forum: HTML
    Replies:
    79
    Views:
    35,391
    Onson
    Dec 20, 2003
  2. chirs

    disable ctrl-v (paste)

    chirs, Nov 28, 2003, in forum: Javascript
    Replies:
    12
    Views:
    1,184
    Lasse Reichstein Nielsen
    Nov 30, 2003
  3. surf_doggie

    Disable drag in ie & FF

    surf_doggie, Nov 25, 2006, in forum: Javascript
    Replies:
    9
    Views:
    118
  4. Flyzone

    disable drag and drop in Firefox

    Flyzone, Jan 17, 2008, in forum: Javascript
    Replies:
    0
    Views:
    176
    Flyzone
    Jan 17, 2008
  5. RJ
    Replies:
    26
    Views:
    479
Loading...

Share This Page