js 点击复制代码

发布时间:2009年08月17日      浏览次数:874 次
1.点击复制标题和地址的代码:
<title>标题</title>
<input type="button" name="Submit" onClick='copyToClipBoard()' value="复制专题地址,传给QQ/MSN上的好友">
<script language="javascript">
function copyToClipBoard(){
var clipBoardContent="";
clipBoardContent+=document.title;
clipBoardContent+="";
clipBoardContent+=this.location.href;
window.clipboardData.setData("Text",clipBoardContent);
alert("复制成功,请粘贴到你的QQ/MSN上推荐给你的好友");
}
</script>
2.点击复制文本框内容的代码:
<script>
function oCopy(obj){
obj.select();
js=obj.createTextRange();
js.execCommand("Copy")
}
</script>
<input onclick="oCopy(this)" value="要copy的内容!">
3.点击复制网址推荐给好友的代码:
<script language="javascript">
function CopyUrl(target){
target.value=myimg.value;
target.select();
js=myimg.createTextRange();
js.execCommand("Copy");
}
function AddImg(target){
target.value="[IMG]"+myimg.value+"[/ img]"; (注:[/ img]中/后面有空格请去掉 )
target.select();
js=target.createTextRange();
js.execCommand("Copy");
}
</script>
<input name=myimg type=hidden id=myimg value="http://www.biz868.com/" />
<input name=imgurl type=text size=32 value="http://www.biz868.com/" />
<input type=button value="点击这里复制本站地址" onclick="CopyUrl(imgurl);" />
<P>如果你喜欢本站,就推荐给你的朋友吧!</P>
4.点击复制网址2
<script type="text/javascript">
function copyText(obj)
{
var rng = document.body.createTextRange();
rng.moveToElementText(obj);
rng.scrollIntoView();
rng.select();
rng.execCommand("Copy");
rng.collapse(false);}
</script>
以下是代码片段:
<span id="tbid">http://www.biz868.com</span>
[<a href="#" onclick="copyText(document.all.tbid)">点击复制</a>]<br/><br/>
<span id="tbid2">http://www.biz868.com </span>
[<a href="#" onclick="copyText(document.all.tbid2)">点击复制</a>]<br/><br/>
免责声明:本站相关技术文章信息部分来自网络,目的主要是传播更多信息,如果您认为本站的某些信息侵犯了您的版权,请与我们联系,我们会即时妥善的处理,谢谢合作!