3

I am trying to copy content to clipboard using https://github.com/zeroclipboard/ZeroClipboard. It seems a good library, but I am getting the error 'Error calling method on NPObject.' when the copy button (a flash) is hovered.

Seems like a flash security problem, but I am able to load the flash content.

Any ideas?

Seth McClaine
  • 9,142
  • 6
  • 38
  • 64
Tukuna
  • 447
  • 3
  • 13

6 Answers6

4

In versions after 1.1.7, if you hosted "ZeroClipboard.swf" on a different domain than the hosting page, you need to set "allowScriptAccess" to "always" other than "sameDomain", also "trustedDomains" should contain current page domain.

ZeroClipboard.setDefaults( { moviePath:'http://YOURSERVER/path/ZeroClipboard.swf',allowScriptAccess: "always",trustedDomains: location.hostname } );
bjornd
  • 22,397
  • 4
  • 57
  • 73
BenL3au
  • 41
  • 1
  • typo: hostaname should be hostname. Oh and thanks, this worked for me. – louisinhongkong Nov 15 '13 at 20:48
  • Note the use of `trustedDomains` rather than `trustedOrigins`. Even though `trustedDomains` is supposedly deprecated, I had to use it in order to get my setup to work (developing locally at `http://localhost:3000` and loading .swf from `"//cdnjs.cloudflare.com/ajax/libs/zeroclipboard/1.1.7/ZeroClipboard.swf"` – Geoffrey Booth Nov 22 '13 at 20:03
  • Thanks for the additional information mate. forgot to change that line ;) – Sagive Dec 11 '13 at 09:55
2

I got it work. It was a same origin security model breech. My web apps subdomain was 'WWW' but the flash content was served from 'CDN'. Just rendered both the contents from same subdomain.

Find more @ https://developer.mozilla.org/en-US/docs/Gecko_Plugin_API_Reference/Scripting_plugins?redirectlocale=en-US&redirectslug=Gecko_Plugin_API_Reference%3AScripting_plugins#NPObject

Thanks.

Tukuna
  • 447
  • 3
  • 13
1

Please add "trustedDomains : [*]"

Tha't how I fixed my problem.

var clip = new ZeroClipboard(document.getElementById("copy-button"), {
    trustedDomains: [ "*" ],
    moviePath: "http://assets.dev.alipay.net/gallery/zeroclipboard/1.2.2/ZeroClipboard.swf"
});

For more details: https://github.com/zeroclipboard/zeroclipboard/issues/103

zyhack
  • 46
  • 5
0

I just updated from 1.0.7 to 1.1.7 yesterday and I'm experiencing the same issue... I'm wondering if they broke something with a commit they did yesterday because this is the only post I've seen about the issue.

~Seth

Seth McClaine
  • 9,142
  • 6
  • 38
  • 64
0

In case this helps anyone else, I managed to make this error go away for my setup (developing locally at http://localhost:3000 and loading the Flash file from cdnjs. CoffeeScript:

if ZeroClipboard?
    ZeroClipboard.setDefaults
        moviePath: "//cdnjs.cloudflare.com/ajax/libs/zeroclipboard/1.1.7/ZeroClipboard.swf"
        trustedOrigins: [window.location.protocol + "//" + window.location.host]
        trustedDomains: window.location.hostname
        allowScriptAccess: "always"

Note that trustedDomains is the key here. Even though it's supposedly deprecated in 1.1.7, removing it (for me at least) causes the dreaded Error calling method on NPObject error to return.

Geoffrey Booth
  • 7,168
  • 5
  • 35
  • 42
0

Or else your domain is not ssl secured i.e your protocol is http instead of https so you should alter your swf link from

https://davidwalsh.name/demo/ZeroClipboard.swf

To

http://davidwalsh.name/demo/ZeroClipboard.swf

For further details please check Cross-Protocol Limitations topic in the following documentation

http://www.kellyjandrews.com/zc/guides/limitations/protocol/

gvgvgvijayan
  • 1,851
  • 18
  • 34