Oncopy Event In Javascript

Oncopy Event Javascript

Sometimes, we are required to react if some user copies some particular element. For example, let’s say that there is some examination going on, and the candidate tries to copy the question so that he/she can search it online. How about if the candidate copies the question, and the question gets changed? Well, this can be handled with the event. As stated earlier, you can do a lot, on the basis of what the requirement says.

We are going to do some small thing over here. Let’s say that we have some questions, and there is some Textarea for the candidate to write the answers to. So, if the candidate copies the question, the question text will change to something random. Let’s try this, and it would be fun!


If you try the above program, you can simply see that there is some question(silly question actually), and there is some Textarea for answering that question. But let’s say that someone copies the question. This is the moment when the copy event triggers and the function copy Alert executes, as per the requirement.
What we are doing here, is just showing an alert, and changing the question text, to some random text.

You can try the above program. It is fun to try these things, and observe the output.