473,806 Members | 2,332 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to detect a Paste action on a textbox?

Is this possible with Javascript in anyway? :)

Dec 2 '06 #1
13 31983
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.javas cript 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.addEvent Listener('load' , function (e)
{
document.getEle mentById('text' ).addEventListe ner('keydown', function
(e)
{
if (e.keyCode == 86) //86 is Paste event
{
alert('You may not paste here !');
e.preventDefaul t();
}
document.getEle mentById('event s').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*********@gma il.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 <stephanemoriau x.NoAd...@wanad oo.fr.invalid>
wrote:
dracogni...@gma il.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...@gm ail.com" <dracogni...@gm ail.com>
wrote:
On Dec 2, 1:18 pm, ASM <stephanemoriau x.NoAd...@wanad oo.fr.invalid>
wrote:
dracogni...@gma il.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.addEvent Listener('load' , function (e)
{
document.getEle mentById('text' ).addEventListe ner('keydown', function
(e)
{
if (e.keyCode == 86 && e.ctrlKey) //86 is 'v' char key
{
e.preventDefaul t();
}
document.getEle mentById('event s').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*********@gma il.com a écrit :
On Dec 2, 1:18 pm, ASM <stephanemoriau x.NoAd...@wanad oo.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*********@gma il.com a écrit :
>On Dec 2, 1:18 pm, ASM <stephanemoriau x.NoAd...@wanad oo.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*********@gma il.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*********@gma il.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.addEvent Listener('load' , function (e)
{
document.getEle mentById('text' ).addEventListe ner('keydown', function
(e)
{
if ((e.keyCode == 86 && e.ctrlKey) || (e.keyCode == 224 && e.metaKey)
{
e.preventDefaul t();
}
document.getEle mentById('event s').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

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

Similar topics

2
1522
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 view widget and my sample application (let's say myapp.py) that imports those tree module to create tree view control inside the main frame. I want in my application to have some method that responds immediately (!!!!) to click action performed...
3
15303
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 someone couldnt paste letters into numeric text box. How this can be done in C#? In Delphi there was method to implement methods wiht message code WM_PASTE, and within that method i could control the contents of the pasted text. Thanks.
1
1500
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
2968
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
1728
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 require a mouseclick if it already contains text to be edited. I am guessing that I would need to trap for this in the Enter Event of this particular textbox. I tried this in the Enter Event of the Textbox, but...
1
1507
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
3180
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 kindly, Dan Sikorsky BA, BSCE, MCS
17
5140
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 about 20 textboxes on the form). Also to ensure that the button can't get used if the cursor isn't in a textbox field. And to ensure the contents of the clipboard are "text" contents that have been cut/copied from one of the textboxes on the form. ...
4
1904
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 some reason the page does not file OnError or OnLoad events. Any help is appreciated. Thanks
0
9719
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9187
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6877
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4329
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3850
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.