3 Javascript- Oncopy Event Handler 


               


Javascript- Oncopy Event Handler


Javascript



The Oncopy event handler in Javascript is an event handler that is triggered when a user copies a piece of information. For example, if you put the oncopy event handler on a paragraph tag, if the user attempts to copy the paragraph, this event handler will be triggered.

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."

First Example

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".

Second Example

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."

Mars exploration

You can use this oncopy event handler according to your imagination, when you believe it would be necessary.


Related Resources

Javascript- Onload Event Handler

Javascript- Onunload Event Handler

Javascript- Onfocus Event Handler

Javascript- Onblur Event Handler

Javascript- Onclick Event Handler

Javascript- Onchange Event Handler

Javascript- Onkeydown Event Handler

Javascript- Onkeyup Event Handler

Javascript- Onmouseover Event Handler

Javascript- Onmousedown Event Handler

Javascript- Onmouseup Event Handler

Javascript- Onmouseout Event Handler

Javascript- Onreset Event Handler

Javascript- Onabort Event Handler



HTML Comment Box is loading comments...