支持firefox的“复制到剪贴板”
2008年5月11日 星期日 轶侠
| 关于电脑
Tags: clipboard, copy, firefox, javascript, 剪贴板, 复制
还在研究codebox,其中的copy to clipboard,因为firefox的安全管理,所以这个功能在firefox里用不了,真的很遗憾
搜索后看到了Jeffothy’s Keyings写的Clipboard Copy在firefox里用了个隐藏的flash来实现代码copy,很暴力,很弓虽。
代码如下:
function copy(inElement) {
if (inElement.createTextRange) {
var range = inElement.createTextRange();
if (range && BodyLoaded==1)
range.execCommand('Copy');
} 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(inElement.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
document.getElementById(flashcopier).innerHTML = divinfo;
}
}
下载:代码中引用的flash文件
想想怎么用到code-box里面,主要是这个引用的url不好确定。