Example of the onbeforecopy Event

Steps to demonstrate the onbeforecopy event:

  1. Select the magenta text.
  2. Right-click the mouse and choose Copy from the shortcut menu.
  3. Switch focus to the text box, and then choose Paste from the shortcut menu.

The copy event is useful for customizing copy behavior. In the example, canceling the default action of copy allows the developer to handle the data transfer. If the default action is not canceled, the text, "copy this text," will be pasted into the text box. If the default action is canceled, then the text, "copy event fired," will be pasted there instead.

copy this text