The information will still be copied by the user, but with this event handler, the page can know when a user can copied something. And we can perform an action based on that.
A user can copy a piece of information either with his/her mouse or by pressing Ctrl + C.
In this code we will give 2 exaples.
The first example is a user copying the paragraph below that says, "When you copy this paragraph, you will get an alert box."
The second example is with an image. If the user copies the image, the alert tag will appear, "You just copied this image."
When you copy this paragraph, you will get an alert box.
The code to create the paragraph above with its oncopy event handler effect is shown below.
<p oncopy="window.alert('You just copied this paragraph');"> When you copy this paragraph, you will get an alert box.
So we have a paragraph and place in the oncopy function. Inside of htis function, we create a window alert box that says, "Just copied this paragraph.
The paragraph, itself, says, "When you copy this paragraph, you will get an alert box".
The second example shown below is with an image.
After a user copies the image, an alert box appears stating, "You just copied this image."
You can use this oncopy event handler according to your imagination, when you believe it would be necessary.