Home  >  Article  >  Web Front-end  >  Code to control the clipboard through JS under IE_javascript skills

Code to control the clipboard through JS under IE_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:48:02956browse

JavaScript can use the window.clipboardData object to process clipboard content
Save to the clipboard method setData(param1, param2)
param1: Data type text or URL, etc.
param2: Data content
From clipboard The method of reading data from the board is getdata(param1)
The method of clearing data is clearData(param1)
The following is an example demonstration


[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute
]

The following is another example implementation Select characters on the page and drag them to the text area
Note that the window.event.dataTransfer object can also handle clipboard content, but it can only be used in drag-and-drop operations

[Ctrl A select all Note:
If you need to introduce external Js, you need to refresh to execute <script> function copyToClipboard() { var d=document.all("source").value; window.clipboardData.setData('text', d); } </script>]<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>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn