VOOZH about

URL: https://www.geeksforgeeks.org/html/html-dom-oncopy-event/

⇱ HTML DOM oncopy Event - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

HTML DOM oncopy Event

Last Updated : 22 Jun, 2023

The HTML DOM oncopy event occurs when the content of an element is copied by the user. It is also applicable to the image, created with the element. It is mostly used with type=”text”.

Note: There are three ways to copy the content of an element: 

  • Press CTRL + C
  • Select "Copy" from the Edit menu in your browser
  • Right-click to display the context menu and select the "Copy" command.

Supported Tags 

  • It supports all HTML elements

Syntax:

In HTML: 

<element oncopy="myScript">

In JavaScript:  

object.oncopy = function(){myScript};

In JavaScript, using the addEventListener() method: 

object.addEventListener("copy", myScript);

Example: Using HTML 

Output: 

πŸ‘ Image
 

Example: Using JavaScript 

Output: 

πŸ‘ Image
 

Example: In JavaScript, using the addEventListener() method: 

Output: 

πŸ‘ Image
 

Supported Browsers: The browsers supported by oncopy Event are listed below: 

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Apple Safari
  • Opera
Comment
Article Tags: