JavaScript 实现完美兼容多浏览器的复制功能代码
分享一段利用JavaScript实现复制功能的代码,兼容多浏览器,兼容IE和火狐浏览器。
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<title>JavaScript复制功能代码,兼容多浏览器</title>
</head>
<scriptlanguage="javascript">
copyValue=function(strValue){
if(isIE()){
clipboardData.setData("Text",strValue);
alert("您已成功复制了此地址");
}else{
copy(strValue);
alert("内容已被复制!");
}
}
functionisIE(number){
if(typeof(number)!=number){
return!!document.all;
}
}
functioncopy(text2copy){
varflashcopier='flashcopier';
if(!document.getElementById(flashcopier)){
vardivholder=document.createElement('div');
divholder.id=flashcopier;
document.body.appendChild(divholder);
}
document.getElementById(flashcopier).innerHTML='';
vardivinfo='<embedsrc="https://img.jbzj.com/demoimg/200910/_clipboard.swf"FlashVars="clipboard='+text2copy+'"width="0"height="0"type="application/x-shockwave-flash"></embed>';//这里是关键
document.getElementById(flashcopier).innerHTML=divinfo;
}
</script>
<divclass="phoinfo">
贴图地址:<inputname="txtPhotoPath"value="www.daimajiayuan.com"id="txtPhotoPath"type="text"size="65"/>
<inputtype="button"name="btnCopy"id="btnCopy"onClick="copyValue('www.daimajiayuan.com');"value="复制"/>
</div>
</body>
</html>
以上所述就是本文给大家的分享的全部内容了,希望大家能够喜欢。
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下