JavaScript 复制功能代码 兼容多浏览器
作者:bea
因此兼容性没得说了,现在用不上的话,先收藏一下吧。 <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>JavaScript 复制功能代码,兼容多浏览器</title> </head> <scr
因此兼容性没得说了,现在用不上的话,先收藏一下吧。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>JavaScript 复制功能代码,兼容多浏览器</title>
</head>
<script language="javascript">
//ie
copyValue=function(strValue)
{
if(isIE())
{
clipboardData.setData("Text",strValue);
alert("您已成功复制了此地址");
}
else
{
copy(strValue);
alert("内容已被复制!");
}
}
function isIE(number)
{
if(typeof(number)!=number)
{
return!!document.all;
}
}
function copy(text2copy)
{
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="http://files./demoimg/200910/_clipboard.swf" FlashVars="clipboard='+text2copy+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';//这里是关键
document.getElementById(flashcopier).innerHTML = divinfo;
}
</script>
<div class="phoinfo">
贴图地址:<input name="txtPhotoPath" value="" id="txtPhotoPath" type="text" size="65" />
<input type="button" name="btnCopy" id="btnCopy" onClick="copyValue('');" value="复制" />
</div>
</body>
</html>
[Ctrl+A 全选 注:
如需引入外部Js需刷新才能执行]
有用 | 无用
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>JavaScript 复制功能代码,兼容多浏览器</title>
</head>
<script language="javascript">
//ie
copyValue=function(strValue)
{
if(isIE())
{
clipboardData.setData("Text",strValue);
alert("您已成功复制了此地址");
}
else
{
copy(strValue);
alert("内容已被复制!");
}
}
function isIE(number)
{
if(typeof(number)!=number)
{
return!!document.all;
}
}
function copy(text2copy)
{
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="http://files./demoimg/200910/_clipboard.swf" FlashVars="clipboard='+text2copy+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';//这里是关键
document.getElementById(flashcopier).innerHTML = divinfo;
}
</script>
<div class="phoinfo">
贴图地址:<input name="txtPhotoPath" value="" id="txtPhotoPath" type="text" size="65" />
<input type="button" name="btnCopy" id="btnCopy" onClick="copyValue('');" value="复制" />
</div>
</body>
</html>
[Ctrl+A 全选 注:
如需引入外部Js需刷新才能执行]
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- javascript 添加和移除函数的通用方法
- JS 用6N±1法求素数 实例教程
- 获取网站跟路径的javascript代码(站点及虚拟目录)
- JavaScript 点击插入文字
- 单选按钮决定链接的网址
- 让链接必须按先后顺序点击的JS代码
- Js文字背景行如流水特效
- 一个链接按两种方式打开两个网址的方法
- 随日期每天自动变换的文本的js特效
- Js 实现文字爬楼滚动效果 结合文本框
- JS CSS制作饱含热情的镶边文字闪烁特效
- Javascript var变量隐式声明方法
- 让你的网站可编辑的实现js代码
- javascript 表单中浏览文件的“浏览”按钮修改
- Javascript 仿歌词智能滚动代码
- JS、CSS文字切换,定时交替,代码精简
- 纯CSS 链接悬停提示效果代码
- javascript 模拟Marquee文字向左均匀滚动代码
- 图片与文字半透明效果 鼠标移上不透明