JavaScript ClipBoard Events


1. cut: This event occurs when the user cuts (or attempts to cut) the content of an element.

Syntax:

    <element oncut=”functionName()” >


Example:

    <p oncut=”myScript()” contenteditable=”true”> Try to cut this text </p>
    <script>
        function myScript()
        {
            alert(“You are trying to cut the text”);
        }
    </script>    


2. copy: This event occurs when the user copies the content of an element.

Syntax:

    <element oncopy=”functionName()” >


Example:

    <p oncopy=”myScript()” > Try to copy this text</p>
    <script>
        function myScript()
        {
            alert(“You are trying to copy the text”);
        }
    </script>    



3. paste: This event occurs when the user pastes some content from clipboard to the document.

Syntax:

    <element onpaste=”functionName()” >


Example:

    <input type=”text” oncopy=”myScript()” />
    <script>
        function myScript()
        {
            alert(“You are trying to paste some text”);
        }
    </script>