js復制到粘貼板,支持IE、Chrome、火狐等多種浏覽器
效果:http:///keleyi/phtml/liulanqi/index.htm
如果要復制所選擇的文本,請參考:http:///a/bjac/e9n33nsb.htm
完整代碼:
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>復制頁面內容到粘貼板,支持IE、Chrome、火狐等多種浏覽器-</title>
<style type="text/css">
body { font-family:arial,sans-serif; font-size:9pt; }
.my_clip_button { width:150px; text-align:center; border:1px solid black; background-color:#ccc; margin:10px; padding:10px; cursor:default; font-size:9pt; }
.my_clip_button.hover { background-color:#eee; }
.my_clip_button.active { background-color:#aaa; }
</style>
<script type="text/javascript" src="http:///keleyi/phtml/liulanqi/index/KeleyiClipboard.js"></script>
<script type="text/javascript">
var clip = null;
function $(id) { return document.getElementById(id); }
function init() {
clip = new ZeroClipboard.Client();
clip.setHandCursor(true);
clip.addEventListener('load', function (client) {
debugstr("准備就緒");
});
clip.addEventListener('mouseOver', function (client) {
// update the text on mouse over
clip.setText($('fe_text').value);
});
clip.addEventListener('complete', function (client, text) {
debugstr("已經把這些文本復制到粘貼板: " + text);
});
clip.glue('d_clip_button', 'd_clip_container');
}
function debugstr(msg) {
var p = document.createElement('p');
p.innerHTML = msg;
$('d_debug').appendChild(p);
}
</script>
</head>
<body onLoad="init()">
<h1>復制頁面內容到粘貼板</h1>
<p><script> document.write("您的浏覽器是: " + navigator.userAgent);</script></p>
<table width="100%">
<tr>
<td width="50%" valign="top">
<!-- Upload Form -->
<table>
<tr>
<td align="right"><b>文本:</b></td>
<td align="left"><textarea id="fe_text" cols=50 rows=5 onChange="clip.setText(this.value)">文本復制,點擊下面的按鈕,將會把這裡的文本復制到粘貼板。http:// 還可以改變這裡的文本試試。</textarea></td>
</tr>
</table>
<br/>
<div id="d_clip_container" style="position:relative">
<div id="d_clip_button" class="my_clip_button"><b>復制到粘貼板</b></div>
</div>
</td>
<td width="50%" valign="top">
<!-- Debug Console -->
<div id="d_debug" style="border:1px solid #aaa; padding: 10px; font-size:9pt;">
<h3>狀態和已經復制的內容:</h3>
</div>
</td>
</tr>
</table>
<br/><br/>
在這裡粘貼,看看是不是已經復制了上面內容<br/>
<textarea id="testarea" cols=50 rows=10></textarea><br/>
<input type=button value="清空" onClick="$('testarea').value = '';"/>
</body>
</html>