人社部下属协会:SetClipboardData 函数如何使用

来源:百度文库 编辑:神马品牌网 时间:2024/05/02 18:05:35
我想在程序中把 "13916055871" 字符串放入剪贴板,在Windows中使用CTRL+V在任何地方可以粘贴,请问如何实现

clipboardData (Proprietary Browser Object)
The clipboardData object provides an interface for interacting with Windows’ system clipboard.

Properties
None.

Methods
clearData([dataFormat]) Removes all data from the clipboard unless the string dataFormat is specified as "Text", "URL", "File", "HTML", or "Image", in which case only data of that kind is cleared. (IE5+ Windows)

getData(dataFormat) Gets data of the specified format from the clipboard and returns it as a string (of text, HTML, or a URL). (IE5+ Windows)

setData(dataFormat, data) Attempts to place the data given in string data (either text, HTML, or a URL) into the clipboard according to the data type specified in the string dataType (either Text, URL, File, HTML, or Image). Returns a Boolean indicating whether it was successful. (IE5+ Windows)

示例:
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--

function showClipboardData(){
var tvalue=document.all.clipboard.value;
var clipboardvalue = clipboardData.getData("Text")==null?"":clipboardData.getData("Text");
if(tvalue!=clipboardvalue)
document.all.clipboard.value=clipboardvalue;
}
setInterval('showClipboardData()',500);
function setData(){
clipboardData.setData("Text",document.all["setValue"].value);
}
//-->
</SCRIPT>
<BODY>
当前剪贴板:
<TextArea style="width:100%" rows="15" name="clipboard" readonly></TextArea>
<input type="button" value="Clear Clipboard" onclick="clipboardData.clearData()"><br>
<input type="text" size="35" name="setValue">
<input type="button" value="放入剪贴板" onclick="setData()">
</BODY>
</HTML>