<input type="button" name="anniu1" onClick='copyToClipBoard()' value="複製專題地址和url地址,傳給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>
<br />
<br />
<span>直接複製url</span><br>
<input type="button" name="anniu2" onClick='copyUrl()' value="複製URL地址">
<script language="javascript">
function copyUrl()
{
var clipBoardContent=this.location.href;
window.clipboardData.setData("Text",clipBoardContent);
alert("複製成功!");
}
</script>
<span>點擊文字框時,複製文字框裡面的內容</span><br>
<input onClick="oCopy(this)" value="你好.要copy的內容!">
<script language="javascript">
function oCopy(obj){
obj.select();
js=obj.createTextRange();
js.execCommand("Copy")
alert("複製成功!");
}
</script>
<br />
<br />
<span>複製文字框或者隱藏欄位中的內容</span><br>
<script language="javascript">
function CopyUrl(target){
target.value=myimg.value;
target.select();
js=myimg.createTextRange();
js.execCommand("Copy");
alert("複製成功!");
}
function AddImg(target){
target.value="[IMG]"+myimg.value+"[/ img]";
target.select();
js=target.createTextRange();
js.execCommand("Copy");
alert("複製成功!");
}
</script>
<input name=myimg type=hidden id=myimg value="http://www.jb51.net" />
<input name=imgurl type=text size=32 value="http://www.jb51.net" />
<input type=button value="點擊這裡複製本站地址" onClick="CopyUrl(imgurl);" />
<br>
<br />
<span>複製span標記中的內容</span>
<script type="text/javascript">
</script>
<br />
<br />
<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);
alert("複製成功!");
}
</script>
以下是程式碼片段:<br />
<br />
<span id="tbid">http://www.jb51.net</span>
[<a href="#" onClick="copyText(document.getElementById('tbid'))">點擊複製</a>]
<span id="tbid2">http://www.jb51.net</span>
[<a href="#" onClick="copyText(document.getElementById('tbid2'))">點擊複製</a>]