Javascript can use the window. clipboardData object to process the clipboard content.
Method for saving to clipboard setData (param1, param2)
Param1: data type, such as text or URL.
Param2: data content
Getdata (param1)
Data clearing method clearData (param1)
The following is an example
<HTML> <HEAD> <TITLE> test operation clipboard </TITLE> </HEAD> <BODY> <button onclick = "copyToClipboard (); "> copy </button> <input type =" text "size = 20 id =" source "value =" Test Data "> <button onclick =" alert (window. clipboardData. getData ('text'); "> display </button> <button onclick =" window. clipboardData. clearData ('text'); "> clear </button> </BODY> </HTML>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
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> <BODY <p id = "mySource" ondragstart = "window. event. dataTransfer. export tallowed = 'move '; "> select and drag us to the following textarea </p> <pre class =" code "id =" myTarget "ondrop =" transferDrop (); "ondragover =" window. event. returnValue = false; "ondragenter =" transferDrag (); "> </textarea> </BODY> </HTML>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]