熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

js復制到剪切板的實例方法

2022-06-13   來源: JSP教程 
這篇文章介紹了復制到剪切板js代碼有需要的朋友可以參考需要   復制代碼 代碼如下:

  
<script type="text/javascript" language="javascript">
//復制到剪切板js代碼
function copyToClipBoard(s) {
//alert(s);
if (windowclipboardData) {
windowclipboardDatasetData("Text" s);
alert("已經復制到剪切板!"+ "n" + s);
} else if (navigatoruserAgentindexOf("Opera") != ) {
windowlocation = s;
} else if (windownetscape) {
try {
netscapesecurityPrivilegeManagerenablePrivilege("UniversalXPConnect");
} catch (e) {
alert("被浏覽器拒絕!n請在浏覽器地址欄輸入about:config並回車n然後將signedappletscodebase_principal_support設置為true");
}
var clip = Componentsclasses[@mozillaorg/widget/clipboard;]createInstance(ComponentsinterfacesnsIClipboard);
if (!clip)
return;
var trans = Componentsclasses[@mozillaorg/widget/transferable;]createInstance(ComponentsinterfacesnsITransferable);
if (!trans)
return;
transaddDataFlavor(text/unicode);
var str = new Object();
var len = new Object();
var str = Componentsclasses["@mozillaorg/supportsstring;"]createInstance(ComponentsinterfacesnsISupportsString);
var copytext = s;
strdata = copytext;
transsetTransferData("text/unicode" str copytextlength * );
var clipid = ComponentsinterfacesnsIClipboard;
if (!clip)
return false;
clipsetData(trans null clipidkGlobalClipboard);
alert("已經復制到剪切板!" + "n" + s)
}
}</script>


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20557.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.