2

Good day, friends. I can't make zeroclipboard working with my page. In HTML page I have:

<script type="text/javascript" src="ZeroClipboard.js"></script> //Script was loaded successfully.

 ...

 <button id="copy_clipboard">Test me</button>
 <script>
  ZeroClipboard.setMoviePath('http://olymp/ZeroClipboard.swf'); //Path correct. It's local php server 
  var clip = new ZeroClipboard.Client();
  clip.setText('test');
  clip.glue('copy_clipboard');
 </script>

This return me an error: ZeroClipboard.setMoviePath is not a function

After deleting

ZeroClipboard.setMoviePath('http://olymp/ZeroClipboard.swf');

I got an error:

ZeroClipboard.Client is not a constructor

Angrybambr
  • 220
  • 3
  • 10
  • Swf has to reside on same domain as that code. Does it? – Hanky Panky Apr 22 '13 at 09:37
  • sure. swf is on the same domain – Angrybambr Apr 22 '13 at 09:43
  • I've tried another variant of using zeroclipboard: var clip = new ZeroClipboard( document.getElementById("copy_clipboard"), { moviePath: "http://olymp/ZeroClipboard.swf", text: "test" } ); clip.setText('test'); It doesn't return any errors. but my text 'test' not copied to the clipboard :( – Angrybambr Apr 22 '13 at 09:47

2 Answers2

1

Hope this would help a little bit:

Try using:

ZeroClipboard.setDefaults({moviePath: 'http://olymp/ZeroClipboard.swf'});

And also:

var clip = new ZeroClipboard();

For your another question, try using :

clip.on('dataRequested', function(client, args){
     clip.setText("YOUR TEXT HERE");
});

instead of using clip.setText alone :)

Stella
  • 69
  • 3
1

sometimes you need to init the zeroclipboard client on document ready

<script src="js/jquery-1.7.1.min.js"></script>
<script src="js/ZeroClipboard.min.js"></script>
<script>
    $(document).ready(function() {
        var client = new ZeroClipboard($('#buttonId'), {
            moviePath : 'util/ZeroClipboard.swf'
        });
    });
</script>
<input type="button" id="buttonId" data-clipboard-target="inputId" />
<input type="text" id="inputId" />

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

ungalcrys
  • 5,242
  • 2
  • 39
  • 23