复制到剪贴板的js代码(兼容ie、firefox、chorme、safari...什么都兼容!)
2008-09-12 11:44
726 查看
今天看到阿里妈妈的复制广告代码到剪贴板的功能不错,看了下他的实现,把它贴出来献给大家。
对于非ie浏览器他是用flash来实现的,js代码如下:
Code
<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="../js/_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(copyText)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
document.getElementById(flashcopier).innerHTML = divinfo;
}
alert('copy成功!');
}
</script>
<input id="inputTest" type="button" value="测试" onclick="copy_code('拷贝成功!帆船书会http://www.fanchuanbook.com')" />
那个flash文件从这里下载:下载
对于非ie浏览器他是用flash来实现的,js代码如下:
Code
<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="../js/_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(copyText)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
document.getElementById(flashcopier).innerHTML = divinfo;
}
alert('copy成功!');
}
</script>
<input id="inputTest" type="button" value="测试" onclick="copy_code('拷贝成功!帆船书会http://www.fanchuanbook.com')" />
那个flash文件从这里下载:下载
相关文章推荐
- 复制到剪贴板的js代码(兼容ie、firefox、chorme、safari...什么都兼容!)
- 复制到剪贴板的js代码(兼容ie、firefox、chorme、safari...什么都兼容!)
- 点击链接复制到剪贴板 js(兼容ie、firefox、chorme、safari...)
- JS复制内容到剪贴板: 兼容IE、Firefox、Chrome、Safari所有浏览器【转】
- 兼容IE与Firefox的js 复制代码
- js 复制内容到剪贴板(兼容IE,Firefox)
- 兼容IE与Firefox的js 复制代码
- js 复制到剪贴板 ,兼容支持火狐firefox 和 ie
- js实现复制到系统剪贴板之IE,firefox兼容版
- 兼容IE与Firefox的js 复制代码
- 复制和粘贴的js代码(IE/FireFox/mozilla/ns)
- js上传图片预览功能代码,兼容IE,FireFox,Chrome浏览器
- JS事件Event元素(兼容IE,Firefox,Chorme)
- JS+flash实现复制功能(兼容IE和firefox)
- FireFox与IE 下js兼容触发click事件的代码
- [转]IE和firefox通用的复制到剪贴板的JS函数
- JS复制内容到剪贴板(兼容FF/Chrome/Safari所有浏览器)
- js复制到剪贴板,兼容ie
- 兼容ie和firefox js关闭代码