Code details JS operation clipboard, details js clipboard

Source: Internet
Author: User

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>

Related Article

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.