Use of javascript copy and paste and clipboardData, clipboarddata
Window. clipboardData can be copied and pasted. Its getData method can be used to read data, and the setData method can be used to set data.
<Script language = "javascript"> function readTxt () {alert (window. clipboardData. getData ("text");} function setTxt () {var t = document. getElementById ("txt"); t. select (); window. clipboardData. setData ('text', t. createTextRange (). text) ;}</script> <input name = "txt" value = "test"> <input type = "button" value = "copy" onclick = "setTxt () "> <input type =" button "value =" read "onclick =" readTxt () ">
How Can I copy and paste data using javascript ???
You can use the: Object .createtextrange(.exe cCommand ("copy") command for copying. You can use:
Window. clipboardData. setData ("text", content source)
The source of the content here is to copy the text in the text box ID to the clipboard. Here, write y. value.
Paste is actually the value Attribute of the target object = y. value
Cutting is based on selection. You must first create a selection area. If the ID of a text box is a, you need:
A.createtextrange(cmd.exe cCommand ("cut ")
To complete the cut.
Select all. If the ID of a text box is B, you only need B. select () to select all text boxes.
How to copy and paste javascript
This function is good and has been made. It is a very practical small function. (In addition, this function is only for IE ):
Step 1: Set the favorites URL:
Javascript: function getSelectedText () {return document. selection. createRange (). text;} function insert () {var input = document. getElementsByTagName ("input"); input [0]. value = window. clipboardData. getData ('text')} if (getSelectedText ()! = "") {Window. clipboardData. setData ('text', getSelectedText (); location = "www.baidu.com"; void (0)} else {insert ()};
Step 2: Set your favorites name
Step 3: If you are using IE7 or later, change IE-> Tools-> Security-> Custom Level-> script-> Allow programmatic access to the clipboard to enable it;
--------
Usage:
1. Select your text on any page and click this favorite link,
2. The page will automatically go to the location page you set, and then you can click this favorite link;
3. as long as there is an input box in this page (if the first box is text, it is a small BUG if it is not easy to say anything else ), you can paste the content in the input box,