Copy and paste operations for javascript instances

Source: Internet
Author: User

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

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.