Copy and paste operations for javascript instances
This article describes how to copy and paste javascript. Share it with you for your reference.
The specific implementation method is as follows:
Copy codeThe Code is as follows: <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 ()">
I hope this article will help you design javascript programs.
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.
You can use javascript to obtain the cut, copy, and paste data.
No!
The reason is simple: This involves personal privacy.
Imagine that you copied or cut some content on your local computer or a.com, and then browsed B .com. If B .com has the ability to obtain the content copied or cut by the user, this would leak the user's personal privacy.
As for pasting, you can use Javascript to listen to Keyboard Events (Ctrl + V/Shift + Ins) in the text box, click the event (onmouseup), or directly listen to onpaste. Before these events are triggered, record the content of the text box. After the event is triggered, compare the content before and after to obtain the pasted data.
The code for getting pasted data is long and I have written it in space. If you are interested, take a look.
Hi.baidu.com/keneks/item/23f09b18d77075088ebde48b