I'm trying to utilize ZeroClipboard (http://code.google.com/p/zeroclipboard/wiki/Instructions) to copy the current URL to the user's clipboard. I know I'm missing something here, but I am not getting any kind of error in the console, nor is it working as of yet:
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>
Any ideas what I'm missing in my code?
Edit: I also tried making the the clip.addEventListener set to window.location. That didn't work either. Could I pull the $('#copyURL') bit out?
clip.addEventListener('mouseOver', function (client) {
// update the text on mouse over
clip.setText( $('#copyURL').window.location );
});
I still haven't figured this one out. Anyone have any ideas on what I'm missing?
Turns out when setting clip.setText to window.location, it was passing an object. Had to start an empty string in order for it to pass properly. It's working now.
clip.addEventListener('mouseOver', function (client) {
// update the text on mouse over
clip.setText(""+window.location);
});