2

I'm trying to use ZeroClipboard in a Rails project, and while the ZeroClipboard.min.js and ZeroClipboard.swf load just fine, when I hover over the div the Flash movie is attached to, I get this error (and nothing works).

Uncaught TypeError: Object #<HTMLEmbedElement> has no method 'setSize'

I'm using, copy-pasted, the example on the GitHub page, plus setting the movie path epath explicitly:

  <html>
  <body>
    <div id="d_clip_button" data-clipboard-text="Copy Me!" title="Click to copy." style="border:1px solid black; padding:20px;">Copy To Clipboard</div>

    <script type="text/javascript" src="/assets/lib/ZeroClipboard.js"></script>
    <script language="JavaScript">
      ZeroClipboard.setMoviePath("/assets/lib/ZeroClipboard.swf");
      var clip = new ZeroClipboard.Client('#d_clip_button');
    </script>
  </body>
  </html>

This works if I run this form a non-Rails server, but when I run it either locally or on my remote staging server, I get the above error.

Any ideas?

Isaac
  • 15,783
  • 9
  • 53
  • 76
  • How sure are you that it's loading the js file? The error message is referring to a function (setSize) that's defined inside that file. Can you post a link to your staging server (or anywhere we can see the error in action)? – jfrank Dec 26 '12 at 20:04
  • My server logs indicate that the file was successfully served, and when I go to the URI of the js file directly, I can download the file. Is there something else I should be looking out for? – Isaac Dec 26 '12 at 20:20
  • I would use Firebug in Firefox or the Inspector tools in Chrome/Safari to see the network request and verify that the js file was loaded. If you have a public page where the error is happening, I can take a look. – jfrank Dec 26 '12 at 20:37
  • http://cl.ly/Lp1B <- shows it is all being loaded, http://cl.ly/LoBo <- shows the error (thank you for your help!) – Isaac Dec 26 '12 at 21:11
  • Do you have a publicly accessible page with the problem? I agree that the js is loading based on those screenshots. – jfrank Dec 27 '12 at 20:47

1 Answers1

3

I have seen this error when using ZeroClipboard with Turbolinks. I was able to work around it by adding:

$(document).on "page:before-change", ->
  ZeroClipboard.destroy()

to application.js.coffee. YMMV.

Martin Harrigan
  • 1,044
  • 11
  • 28