473,320 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to detect a Paste action on a textbox?

Is this possible with Javascript in anyway? :)

Dec 2 '06 #1
13 31878
ha******@gmail.com 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/
Dec 2 '06 #2
On Dec 2, 6:47 am, halbe...@gmail.com 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>

Dec 2 '06 #3
ASM
dr*********@gmail.com a écrit :
On Dec 2, 6:47 am, halbe...@gmail.com 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
Dec 2 '06 #4
On Dec 2, 1:18 pm, ASM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>
wrote:
dracogni...@gmail.com a écrit :
On Dec 2, 6:47 am, halbe...@gmail.com 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

P.S. Ton mac est si vieux ?

--
Naixn.

Dec 2 '06 #5
On Dec 2, 1:30 pm, "dracogni...@gmail.com" <dracogni...@gmail.com>
wrote:
On Dec 2, 1:18 pm, ASM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>
wrote:
dracogni...@gmail.com a écrit :
On Dec 2, 6:47 am, halbe...@gmail.com 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

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 " :p ] ).

--
Naixn.

Dec 2 '06 #6
ASM
dr*********@gmail.com a écrit :
On Dec 2, 1:18 pm, ASM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>
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
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
Dec 2 '06 #7
ASM wrote :
dr*********@gmail.com a écrit :
>On Dec 2, 1:18 pm, ASM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>
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
>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
Dec 2 '06 #8
ASM
dr*********@gmail.com 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
Dec 2 '06 #9
ASM wrote :
dr*********@gmail.com 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
Dec 2 '06 #10
ha******@gmail.com wrote:
Is this possible with Javascript in anyway? :)
IE/Win has events for that:
<http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/events/onbeforepaste.asp>
<http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/events/onpaste.asp>

Mozilla has the input event/oninput event handler that fires for any
kind of input, including a paste operation.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Dec 2 '06 #11
dr*********@gmail.com said the following on 12/2/2006 6:09 AM:
On Dec 2, 6:47 am, halbe...@gmail.com 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 :
No it doesn't. Open your test page, put the cursor in the textarea, and
press the key combination of <Shift><Insert>

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 2 '06 #12
Randy Webb wrote :
dr*********@gmail.com said the following on 12/2/2006 6:09 AM:
>On Dec 2, 6:47 am, halbe...@gmail.com 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 :

No it doesn't. Open your test page, put the cursor in the textarea, and
press the key combination of <Shift><Insert>
In fact... too bad there's no onPaste event ( apart from IE I mean ).
Plus, right-click and paste doesn't work either.

I don't know, then, how to prevent/handle paste in (Gecko/Presto/Webcore)-based
browsers?

--
Naixn
http://fma-fr.net
Dec 2 '06 #13
<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>

When I cut-and-paste this and run on IE, I get a 'object does not
support this property or metod'. Is something getting cut-off in my
code above?

Dec 2 '06 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ringwraith | last post by:
Hello! How to detect in Python that some click action was performed in some module imported by my main module? Let's assume I have a tree.py module that implements all functionality of a tree...
3
by: Radovan Radic | last post by:
Hello all, I am new to .NET and a i am moving from Delphi (finally!) to C#. Now, i am trying to develop custom TextBox for numeric input. I have done it almost, now i need to prevent paste so...
1
by: Andrés Ortíz | last post by:
Hi I need that my TextBox don't work for copy-paste (Ctrl+C) and other forms that we used for copy text. Thanks
2
by: Steve | last post by:
Hi all, Is it possible to disable pasting from the clipboard into a textbox ?? I can't find a property for it but I guess it must be possible. thanks Steve
2
by: Rich | last post by:
Hello, I need to trap/detect when a textbox is entered via the tabkey. If the textbox is not empty when entered via the tabkey then set focus to next textbox. To enter that textbox would then...
1
by: Julian | last post by:
Hi In VB .Net how do you prevent characters apart from numbers being pasted into a text box? Julian
2
by: Dan Sikorsky | last post by:
How can we tell if the value in a FormView EditItemTemplate TextBox has changed from its initial value so that we know if we have to update the corresponding db table column value? -- Thank you...
17
by: Steve | last post by:
I'm trying to code cut, copy, and paste in vb 2005 so that when the user clicks on a toolbar button, the cut/copy/paste will work with whatever textbox the cursor is current located in (I have...
4
by: sid | last post by:
Can someone tell me how to detect "Action Cancelled" page with out polling. I have a frame set and I want to make sure the other frame is displaying what it is supposed to without polling. For...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.