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