Dom_window Object Properties--clipboarddata Object manipulation code _javascript tips

Source: Internet
Author: User
Clipboarddata objects
Provides access to the predefined clipboard format for use in editing operations.

Member table

Method description
ClearData deletes one or more data formats from the Clipboard by DataTransfer or Clipboarddata objects.
GetData gets the data in the specified format from the Clipboard through the DataTransfer or Clipboarddata object.
SetData assigns data to DataTransfer or Clipboarddata objects in the specified format.

sample
The following example uses the SetData and GetData methods of the Clipboarddata object to perform a cut-and-paste operation through the shortcut menu.
Copy Code code as follows:

<SCRIPT>
var bresult;
Select the text you want to cut. Trailing spaces in the text selection in the Cut event cause the clipping
The Select shortcut menu item remains invalid.
function Fnload () {
var r = Document.body.createTextRange ();
R.findtext (Osource.innertext);
R.select ();
}

Enable the Cut shortcut menu item, which defaults to invalid when on DIV
function Fnbeforecut () {
Event.returnvalue = false;
}

Assigns data to a Window.clipboarddata object in text format.
Displays the result of the SetData method (Boolean) in the following input box.
function Fncut () {
Event.returnvalue = false;
Bresult = Window.clipboardData.setData ("Text", Osource.innertext);
Osource.innertext = "";
Ttext.innertext + = Bresult;
}

Enable the Paste shortcut menu item, which is also invalid by default when on DIV
function Fnbeforepaste () {
Event.returnvalue = false;
}

Cancel returnvalue in Onpaste to enter text, which has the default
's behavior.
function Fnpaste () {
Event.returnvalue = false;
Otarget.innertext = Window.clipboardData.getData ("Text");
}

</SCRIPT>
</HEAD>

<body onload= "Fnload ()" Topmargin=0 leftmargin=0 bgproperties= "fixed" bgcolor= "#FFFFFF"
link= "#000000" vlink= "#808080" alink= "#000000" >

<div class= "Clssource" id= "Osource" onbeforecut= "Fnbeforecut ()" <span style= "COLOR: #ff0000" >oncut</span >= "Fncut ()" > select and cut this text </DIV>
<div class= "Clstarget" id= "Otarget" onbeforepaste= "Fnbeforepaste ()" <span style= "COLOR: #ff0000" >onpaste </span>= "Fnpaste ()" > Paste the text here </DIV><BR>

<span class= "Clsdata" >setdata results:</span>
<input class= "Clstext" id= "Ttext" type= "text" READONLY value= "" size= "6" tabindex= "-1" >

</BODY>

Note the oncut, onpaste events in the code

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.