转载时请标明文章原始出处和作者信息, 作者: lostsnow.
http://www.lsproc.com/blog/copy_to_clipboard/
从 discuz! 里扒出来的(简易实现), 代码如下:
01.
var
clipboardswfdata;
02.
03.
var
setcopy_gettext =
function
(){
04.
clipboardswfdata = document.getElementById(
'data'
).value;
05.
window.document.clipboardswf.SetVariable(
'str'
, clipboardswfdata);
06.
}
07.
08.
var
floatwin =
function
(){
09.
alert(
'copy success, '
+ clipboardswfdata);
10.
}
1.
<
input
type
=
"text"
name
=
"data"
value
=
"xxxxx11111"
id
=
"data"
/>
2.
<
div
id
=
"clipboard_content"
>
3.
<
span
class
=
"clipinner"
id
=
"clipinner"
>点此复制到剪贴板
4.
<
embed
name
=
"clipboardswf"
class
=
"clipboardswf"
id
=
"clipboardswf"
onmouseover
=
"setcopy_gettext()"
devicefont
=
"false"
src
=
"./clipboard.swf"
menu
=
"false"
allowscriptaccess
=
"sameDomain"
swliveconnect
=
"true"
wmode
=
"transparent"
type
=
"application/x-shockwave-flash"
height
=
"20"
width
=
"100"
></
span
>
5.
</
div
>
1.
<style type=
"text/css"
>
2.
body {
font-size
:
12px
;}
3.
.clipinner {
position
:
relative
;}
4.
.clipboardswf {
position
:
absolute
;
left
:
0
;
top
:
0
;}
5.
</style>
实现稍微有些恶心, 用 onmouseover 事件往 flash 中传递数据
另: 没有对ie单独处理, ie中推荐使用 window.clipboardData
演示地址: http://www.lsproc.com/demo/cliboard/demo.html
演示代码下载: http://www.lsproc.com/wiki/_media/snippets:clipboard.zip
另: google code 上有个 zeroclipboard 的项目, 如果想要方便的话, 也可以使用
地址: http://code.google.com/p/zeroclipboard/