JS+SWF实现浏览器复制

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>同时支持iexplorer和firefox的javascript复制拷贝剪贴板方法</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script>
//copy信息到剪贴板
function cpIt(s){
	if (window.clipboardData) {
		window.clipboardData.setData("Text",s);
	}
	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(s)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
		document.getElementById(flashcopier).innerHTML = divinfo;
	}
	alert("\r\n信息:"+s+"\r\n\r\n恭喜您,您需要的信息已经被成功复制到剪贴板了!\r\n\r\n贴心小提示:(1) 按 Ctrl+v 可以将上面信息粘贴到您指定的位置。\r\n\r\n                        (2) 按空格键可迅速关闭本提示框");
}
</script>
</head><body>
<input type="text" name="idCopyText" id="idCopyText" value="要拷贝的文字..."><input type="button" value="拷贝到剪贴板" onclick="cpIt(document.getElementById('idCopyText').value);">
</body></html>

你可能感兴趣的:(js,Flash,复制)