Code details JS operation clipboard, details js clipboard
Javascript allows you to easily operate the client clipboard content, but it is only applicable to IE 5 and later browsers.
Javascript can use the window. clipboardData object to process the clipboard content.
The setData (param1, param2) method for saving to the clipboard ).
Param1: data type, such as text or URL.
Param2: data content.
Getdata (param1)
Data clearing method clearData (param1)
<HTML> <HEAD> <TITLE> test operation clipboard </TITLE> </HEAD> <script> function copyToClipboard () {var d = document. all ("source "). value; window. clipboardData. setData ('text', d) ;}</script> <BODY> <button onclick = "copyToClipboard (); "> copy </button> <input type =" text "size = 20 id =" source "value =" Test Data "> <br> <button onclick =" alert (window. clipboardData. getData ('text'); "> display </button> <button onclick =" window. clipboardData. cle ArData ('text'); "> clear </button> </BODY> </HTML> the following example shows how to select a character on the page and drag it to the character area. Note that the window. event. dataTransfer object can also process the clipboard content, but it can only be used in the drag-and-drop operation. <HTML> <HEAD> <TITLE> test operation clipboard 2 </TITLE> </HEAD> <script> function transferDrop () {window. event. srcElement. innerText = window. event. dataTransfer. getData ("text"); window. event. returnValue = false;} function transferDrag () {window. event. dataTransfer. dropEffect = 'move '; window. event. returnValue = false ;}</script> <BODY> <p id = "mySource" ondragstart = "window. event. dataTransfer. export tallowed = 'move '; "> select and drag us to the following textarea </p> <textarea id =" myTarget "ondrop =" transferDrop (); "ondragover =" window. event. returnValue = false; "ondragenter =" transferDrag (); "> </textarea> </BODY> </HTML>