JS复制文字到剪贴板

HTML代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
<title>无标题文档</title>
    
<script type="text/javascript">
    
function copy_code(copyText) 
    {
        
if (window.clipboardData) 
        {
            window.clipboardData.setData(
"Text", copyText)
        } 
        
else 
        {
            
var flashcopier = 'flashcopier';
            
if(!document.getElementById(flashcopier)) 
            {
              
var divholder = document.createElement('div');
              divholder.id 
= flashcopier;
              document.body.appendChild(divholder);
            }
            document.getElementById(flashcopier).innerHTML 
= '';
            
var divinfo = '<embed src="_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(copyText)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
            document.getElementById(flashcopier).innerHTML 
= divinfo;
        }
        alert(
'copy成功!');
    }
    
</script>
</head>

<body>
    
<input id="inputTest" type="button" value="测试" onclick="copy_code('fdsdffffffff放松点士大夫士大夫是地方')" />
</body>
</html>

配套FLASH文件:点击下载

原文地址:https://www.cnblogs.com/wangpei/p/1656586.html