複製按鈕適用於各常用瀏覽器

  • 3357
  • 0
  • 2012-03-29

摘要:複製按鈕適用於各常用瀏覽器

不適用於 chrome

 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<html lang="zh-TW"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title></title> 
<script type="text/javascript"> 
function copyToClipboard(txt) {
 if(window.clipboardData) {
 window.clipboardData.setData("text", txt);} 
else if(navigator.userAgent.indexOf("Opera") != -1) {
window.location = txt;}
else if(window.netscape) {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");}
catch(e) {
alert("存取剪貼簿被瀏覽器拒絕!\n請在網址列輸入'about:config'開啟\n然後將'signed.applets.codebase_principal_support'設定為'true'"); }
var gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper); 
gClipboardHelper.copyString(txt); } } 
</script> 
</head> 
<body> 
<input type="button" onclick="copyToClipboard('要複製的東東')" value="點我可複製" /> 
</body> 
</html>