zeroclipboard not working

so I'm trying to use this plugin:

http://code.google.com/p/zeroclipboard/wiki/Instructions

which basically allows you to set clipboard text via javascript by using a flash movie trick

I did

    ZeroClipboard.setMoviePath( '/pathtoswf/zeroclipboard.swf' );
    var clip = new ZeroClipboard.Client();
    clip.setHandCursor( false );
    clip.setText('lalalalala');
    clip.glue( 'i_container', 'i_button' ); 
    clip.addEventListener( 'onLoad', function(){ alert('loaded baby'); } );
    clip.addEventListener('onMouseDown', function(){ alert('mouse is down'); });
    clip.addEventListener('onComplete', function(){ alert('text got copied to clipboard'); });

with the html

<div id="i_container" style="position:relative">
<div id="i_button">
Something
</div>
</div>

zeroclipboard js is loaded just fine

so when I run this, it alerts "loaded baby" just fine so the flash also gets displayed fine but then when I click on the "something" text it doesn't alert mouse is down nor does it alert that the text got copied to the clipboard, nor is the text actually get copied to clipboard

what did I do wrong?

Answers:

Answer

Are you running from a local file on disk? As it says , Zero Clipboard might not work from local disks due to the security restrictions placed by Adobe. You may need to have an http:// or https:// url.

You can work around this by going here and adding the path to your local "ZeroClipboard.swf" file to the trusted files list. You could also try the "allow all" option.

Having said the above, when I installed it in my dev environment I didn't do any of that!! I just tested it using the "Complete Example" provided in the wiki instructions. I stuck the .swf file in the same directory as the webpage itself and it worked fine. Maybe try a simplified cut-and-paste test first up.

The demo example also has function(client){... where you just have function(){... for your addEventListener handlers. That would probably explain why you get no alerts for onMouseDown and onComplete, although I'm not sure why the alert worked for the onLoad.

Answer

for me it works when I init the zeroclipboard client on document ready

...
<script>
    $(document).ready(function() {
        var client = new ZeroClipboard($('#buttonId'), {
            moviePath : 'util/ZeroClipboard.swf'
        });
    });
</script>
...

will copy in cplipboard the contents of the input text, for me it worked also for localhost

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.