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

onbeforecut event | beforecut event

Browser support:
Occurs before the selection is cut from the document and provides a possibility to enable the Cut menu item.
The onbeforecut event is useful if you want to enable the Cut menu item for texts that are not in an editable element (textarea, input:text, input:file and input:password) and not in an editable region (see the contentEditable and designMode properties). To enable the Cut menu item for an element, return false from an event handler for the onbeforecut event on it.
  • In Internet Explorer, if the user selects the Cut menu item for a non-editable content, the oncut event is fired and the selected content is cut.
  • In Google Chrome and Safari, the oncut event is fired but the selected content is left untouched.
If you want to implement the functionality of the Cut operation in Google Chrome and Safari, see the page for the clipboardData object. It contains a cross-browser example that shows how to access the clipboard. To remove the contents of the selection from the document, use the deleteFromDocument method.
  • In Internet Explorer, the onbeforecut event occurs on the deepest element in the DOM hierarchy that contains the entire selection.
  • In Google Chrome and Safari, the onbeforecut event occurs on the deepest element in the DOM hierarchy that contains the start point of the selection.

How to register:

In HTML:
<ELEMENT onbeforecut="handler">

In JavaScript:
object.onbeforecut = handler;
object.addEventListener ("beforecut", handler, useCapture);
9
object.attachEvent ("onbeforecut", 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 onbeforecut event:

  • Pressing CTRL + X.
  • Opening the Edit menu.
  • Opening the context menu (right mouse click).

Events related to the clipboard:

Example HTML code 1:

This example shows how to enable the Cut menu item for a non-editable content:
<head>
    <script type="text/javascript">
        function EnableCut () {
            return false;   // enable the Cut menu item
        }

        function OnCut () {
            alert ("An oncut event has occurred!");
        }
    </script>
</head>
<body>
    <div onbeforecut="return EnableCut ()" oncut="OnCut ()">
        Select some text on this page and use the Cut menu item in the Edit menu 
        or in the context menu (right mouse click) to cut the selected content from the document.
    </div>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content