Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > How to detect a Paste action on a textbox?

Reply
Thread Tools

How to detect a Paste action on a textbox?

 
 
halbenca@gmail.com
Guest
Posts: n/a
 
      12-02-2006
Is this possible with Javascript in anyway?

 
Reply With Quote
 
 
 
 
Randy Webb
Guest
Posts: n/a
 
      12-02-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) said the following on 12/2/2006 12:47 AM:
> Is this possible with Javascript in anyway?


Is what possible?

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
 
Reply With Quote
 
 
 
 
dracognizer@gmail.com
Guest
Posts: n/a
 
      12-02-2006
On Dec 2, 6:47 am, (E-Mail Removed) wrote:
> Is this possible with Javascript in anyway?


Yes, it is possible to detect a paste action.
Here's a simple exemple, preventing to paste in a textarea :

<html>
<head>
<script>
window.addEventListener('load', function (e)
{
document.getElementById('text').addEventListener(' keydown', function
(e)
{
if (e.keyCode == 86) //86 is Paste event
{
alert('You may not paste here !');
e.preventDefault();
}
document.getElementById('events').innerHTML += e.keyCode + ' ' +
e.which + '<br />';
}, false);
}, false);
</script>
</head>

<body>
<textarea id="text">
</textarea>
<div id="events">
</div>
</body>
</html>

 
Reply With Quote
 
ASM
Guest
Posts: n/a
 
      12-02-2006
(E-Mail Removed) a écrit :
> On Dec 2, 6:47 am, (E-Mail Removed) wrote:
>> Is this possible with Javascript in anyway?

>
> Yes, it is possible to detect a paste action.
> Here's a simple exemple, preventing to paste in a textarea :


How do you expect to tape 'v' ? or 'V' ?

Anyway,
that doesn't work at all !

report under textbox tells me : 224 224



--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
 
Reply With Quote
 
dracognizer@gmail.com
Guest
Posts: n/a
 
      12-02-2006
On Dec 2, 1:18 pm, ASM <(E-Mail Removed)>
wrote:
> (E-Mail Removed) a écrit :
>
> > On Dec 2, 6:47 am, (E-Mail Removed) wrote:
> >> Is this possible with Javascript in anyway?

>
> > Yes, it is possible to detect a paste action.
> > Here's a simple exemple, preventing to paste in a textarea :How do you expect to tape 'v' ? or 'V' ?

>
> Anyway,
> that doesn't work at all !
>
> report under textbox tells me : 224 224
>
> --
> Stephane Moriaux et son (moins) vieux Mac déjà dépassé
> Stephane Moriaux and his (less) old Mac already out of date


Oups... You're totally rights... >_<
I'm sorry i wasn't careful enough about that...

I'm going to see if I can do something about it

P.S. Ton mac est si vieux ?

--
Naixn.

 
Reply With Quote
 
dracognizer@gmail.com
Guest
Posts: n/a
 
      12-02-2006
On Dec 2, 1:30 pm, "(E-Mail Removed)" <(E-Mail Removed)>
wrote:
> On Dec 2, 1:18 pm, ASM <(E-Mail Removed)>
> wrote:
>
>
>
> > (E-Mail Removed) a écrit :

>
> > > On Dec 2, 6:47 am, (E-Mail Removed) wrote:
> > >> Is this possible with Javascript in anyway?

>
> > > Yes, it is possible to detect a paste action.
> > > Here's a simple exemple, preventing to paste in a textarea :How do you expect to tape 'v' ? or 'V' ?

>
> > Anyway,
> > that doesn't work at all !

>
> > report under textbox tells me : 224 224

>
> > --
> > Stephane Moriaux et son (moins) vieux Mac déjà dépassé
> > Stephane Moriaux and his (less) old Mac already out of dateOups... You're totally rights... >_<

> I'm sorry i wasn't careful enough about that...
>
> I'm going to see if I can do something about it
>
> P.S. Ton mac est si vieux ?
>
> --
> Naixn.


<script>
window.addEventListener('load', function (e)
{
document.getElementById('text').addEventListener(' keydown', function
(e)
{
if (e.keyCode == 86 && e.ctrlKey) //86 is 'v' char key
{
e.preventDefault();
}
document.getElementById('events').innerHTML += e.keyCode + ' ' +
e.which + '<br />';
}, false);
}, false);
</script>

Here it is.
I forgot to put the "e.ctrlKey" check ( to check wether control key was
pressed, or not.

Thing is I don't have any way to try javascript on Safari ( as there's
no JavaScriptCore port on Linux, apart from KHTML, which begins to
differs a lot from WebCore... ).
What is 224 ? Ctrl+V keycode, or V keycode ?

Is the e.ctrlKey working with safari ? Since I know you have to "pomme
+ v" to paste ( sorry I don't remember the english equivalent for
'pomme' [ I just know it's not " Apple " ] ).

--
Naixn.

 
Reply With Quote
 
ASM
Guest
Posts: n/a
 
      12-02-2006
(E-Mail Removed) a écrit :
> On Dec 2, 1:18 pm, ASM <(E-Mail Removed)>
> wrote:
>> that doesn't work at all !


> Oups... You're totally rights... >_<
> I'm going to see if I can do something about it


> P.S. Ton mac est si vieux ?


The so noisy G4 MDD (1,25Mhz OS 10.3.9) 2 years old.

P.S. : qu'est-ce qu'il a le Messenger de ton Mozilla ?
(pour ne pas gommer la signature de l'envoyeur dans les réponses)

--
Stephane Moriaux et son moins vieux Mac déjà dépassé
Stephane Moriaux and his less old Mac already out of date
 
Reply With Quote
 
naixn
Guest
Posts: n/a
 
      12-02-2006
ASM wrote :
> (E-Mail Removed) a écrit :
>> On Dec 2, 1:18 pm, ASM <(E-Mail Removed)>
>> wrote:
>>> that doesn't work at all !

>
>> Oups... You're totally rights... >_<
>> I'm going to see if I can do something about it

>
>> P.S. Ton mac est si vieux ?

>
> The so noisy G4 MDD (1,25Mhz OS 10.3.9) 2 years old.
>
> P.S. : qu'est-ce qu'il a le Messenger de ton Mozilla ?
> (pour ne pas gommer la signature de l'envoyeur dans les réponses)
>


In fact, it's an old one!

Please refer to my previous post to check the changes I made.
Maybe you'll also be able to answer my safari-specific questions

P.S. : Tout simplement que j'utilisais google newsgroups.
C'est maintenant corrigé

--
Naixn
http://fma-fr.net
 
Reply With Quote
 
ASM
Guest
Posts: n/a
 
      12-02-2006
(E-Mail Removed) a écrit :
>
> Here it is.
> I forgot to put the "e.ctrlKey" check ( to check wether control key was
> pressed, or not.


On Mac Control key is not used to copy/paste/etc
we use touch Command (Pomme).

With FireFox, with Command + v and Command + z
keyCode returns 224
Command associated with others touchs (x, a, p, ... ) keyCode returns
correspondant character/touch key code.

> Thing is I don't have any way to try javascript on Safari


My tests show Safari doesn't report touch Command (Pomme - Apple)
nor keyCode as if anything was pressed.

My test with Opera : Opera doesn't give a special code for
Command+v Command+c (normal letter key code)

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
 
Reply With Quote
 
naixn
Guest
Posts: n/a
 
      12-02-2006
ASM wrote :
> (E-Mail Removed) a écrit :
>>
>> Here it is.
>> I forgot to put the "e.ctrlKey" check ( to check wether control key was
>> pressed, or not.

>
> On Mac Control key is not used to copy/paste/etc
> we use touch Command (Pomme).
>
> With FireFox, with Command + v and Command + z
> keyCode returns 224
> Command associated with others touchs (x, a, p, ... ) keyCode returns
> correspondant character/touch key code.
>
>> Thing is I don't have any way to try javascript on Safari

>
> My tests show Safari doesn't report touch Command (Pomme - Apple)
> nor keyCode as if anything was pressed.
>
> My test with Opera : Opera doesn't give a special code for
> Command+v Command+c (normal letter key code)
>


Well, let's correct it :

<script>
window.addEventListener('load', function (e)
{
document.getElementById('text').addEventListener(' keydown', function
(e)
{
if ((e.keyCode == 86 && e.ctrlKey) || (e.keyCode == 224 && e.metaKey)
{
e.preventDefault();
}
document.getElementById('events').innerHTML += e.keyCode + ' ' +
e.which + '<br />';
}, false);
}, false);
</script>

Ok now, how does it work with you, with this correction ?

--
Naixn
http://fma-fr.net
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Can we call an Action from another Action in struts??? vyshu Java 1 04-27-2007 09:19 AM
Struts mapping action to action??? runescience Java 3 02-07-2006 04:07 PM
Struts Forward to an Action from an to Action and URLs rjweytens Java 6 06-25-2004 01:49 PM
Struts Static Action Form vs Dyanamic Action Form Joe Bloggs Java 1 08-03-2003 02:30 AM



Advertisments