我正在尝试利用 ZeroClipboard (http://code.google.com/p/zeroclipboard/wiki/Instructions) 将当前 URL 复制到用户的剪贴板。我知道我在这里遗漏了一些东西,但我在控制台中没有收到任何错误,也没有工作:
JavaScript
<script src="/js/zero-clipboard.js"></script>
<script>
var clip = null;
ZeroClipboard.setMoviePath( '/ZeroClipboard10.swf' );
function $(id) { return document.getElementById(id); }
function init() {
clip = new ZeroClipboard.Client();
clip.setHandCursor( true );
clip.addEventListener('load', function (client) {
debugstr("Flash movie loaded and ready.");
});
clip.addEventListener('mouseOver', function (client) {
// update the text on mouse over
clip.setText( $('#copyURL').href );
});
clip.addEventListener('complete', function (client, text) {
debugstr("Copied text to clipboard: " + text );
});
clip.glue( 'copyURL', 'copyURLContainer' );
}
function debugstr(msg) {
var p = document.createElement('p');
p.innerHTML = msg;
$('d_debug').appendChild(p);
}
</script>
HTML:
<div id="copyURLContainer">
<a id="copyURL" href="javascript:window.location">COPY URL</a>
</div>
任何想法我在我的代码中缺少什么?
编辑:我还尝试将clip.addEventListener 设置为window.location。那也没有用。我可以拉出 $('#copyURL') 位吗?
clip.addEventListener('mouseOver', function (client) {
// update the text on mouse over
clip.setText( $('#copyURL').window.location );
});
这个我还没想通。有人对我缺少的东西有任何想法吗?