You are here: Reference > JavaScript > client-side > event handling > events > onbeforecopy

onbeforecopy event | beforecopy event

Browser support:
Occurs before the selection is copied to the clipboard and before the oncopy event.
  • In Internet Explorer, the onbeforecopy event occurs on the deepest element in the DOM hierarchy that contains the entire selection.
  • In Google Chrome and Safari, the onbeforecopy event occurs on the deepest element in the DOM hierarchy that contains the start point of the selection.
If you need access to the clipboard in Internet Explorer, use the clipboardData object.

How to register:

In HTML:
<ELEMENT onbeforecopy="handler">

In JavaScript:
object.onbeforecopy = handler;
object.addEventListener ("beforecopy", handler, useCapture);
9
object.attachEvent ("onbeforecopy", handler);
You can find the related objects in the Supported by objects section below.
The event object is accessible to all event handlers in all browsers. The properties of the event object contain additional information about the current event. To get further details about these properties and the possible event handler registration methods, please see the page for the event object.
For a complete list of events, see the page for Events in JavaScript.

Basic information:

Bubbles Yes
Cancelable Yes
Event object
DragEvent
9
Event

Actions that invoke the onbeforecopy event:

In Internet Explorer:
  • Pressing CTRL + C.
  • Opening the Edit menu.
  • Opening the context menu (right mouse button).
In Google Chrome and Safari:
  • Pressing CTRL + C.
  • Selecing the Copy command from the Edit menu or if the Copy command is inactive, then opening the Edit menu.
  • Opening the context menu (right mouse button).

Events related to the clipboard:

Example HTML code 1:

This example illustrates the use of the onbeforecopy event:
<head>
    <script type="text/javascript">
        function OnBeforeCopy () {          
            alert ("An onbeforecopy event has occurred.");
            if (window.clipboardData) {
                var data = window.clipboardData.getData ("Text");
                alert ("The contents of the clipboard before the copy operation are\n" + data);
            }
        }
    </script>
</head>
<body onbeforecopy="OnBeforeCopy ()">
    Select some text on this page and press CTRL + C!
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content