复制内容到用户的剪贴板
Ghost 发表于 [2005-11-23 16:06]
一段可以将内容复制到用户的剪贴板的代码:
1.将下面的代码复制到 <head> 内
---------------------------------------------------------------
<style>
.highlighttext{
background-color:yellow;
font-weight:bold;
}
</style>
<script language="Javascript">
<!--
//specify whether contents should be auto copied to clipboard (memory)
//Applies only to IE 4+
//0=no, 1=yes
var copytoclip=1
function HighlightAll(theField) {
var tempval=eval("document."+theField)
tempval.focus()
tempval.select()
if (document.all&©toclip==1){
therange=tempval.createTextRange()
therange.execCommand("Copy")
window.status="Contents highlighted and copied to clipboard!"
setTimeout("window.status=''",1800)
}
}
//-->
</script>
--------------------------------------------------------------
2.将下面的代码复制到 <body>
--------------------------------------------------------------
<form name="test">
<a class="highlighttext" href="javascript:HighlightAll('test.select1')">Select All</a><br>
<textarea name="select1" rows=10 cols=35 >This is some text. This is some text. This is some text. This is some text.</textarea>
</form>
Ghost 发表于 [2005-11-23 16:06]
一段可以将内容复制到用户的剪贴板的代码:
1.将下面的代码复制到 <head> 内
---------------------------------------------------------------
<style>
.highlighttext{
background-color:yellow;
font-weight:bold;
}
</style>
<script language="Javascript">
<!--
//specify whether contents should be auto copied to clipboard (memory)
//Applies only to IE 4+
//0=no, 1=yes
var copytoclip=1
function HighlightAll(theField) {
var tempval=eval("document."+theField)
tempval.focus()
tempval.select()
if (document.all&©toclip==1){
therange=tempval.createTextRange()
therange.execCommand("Copy")
window.status="Contents highlighted and copied to clipboard!"
setTimeout("window.status=''",1800)
}
}
//-->
</script>
--------------------------------------------------------------
2.将下面的代码复制到 <body>
--------------------------------------------------------------
<form name="test">
<a class="highlighttext" href="javascript:HighlightAll('test.select1')">Select All</a><br>
<textarea name="select1" rows=10 cols=35 >This is some text. This is some text. This is some text. This is some text.</textarea>
</form>