473,399 Members | 3,401 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,399 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 31888
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.