Code for controlling the clipboard using JS in IE

Source: Internet
Author: User

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]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.