简体   繁体   English

无法加载ZeroClipboard SWF

[英]ZeroClipboard SWF does not load

ZeroClipboard.setMoviePath( "/zeroclipboard/ZeroClipboard.swf" );
var clip = new ZeroClipboard.Client();
clip.setText( $('textarea#download_me').text() );
clip.glue( 'clip' );

I'm using the popular ZeroClipboard plugin to copy content to user's clipboard. 我正在使用流行的ZeroClipboard插件将内容复制到用户的剪贴板。 It works perfectly in the dev enviornment as well as on domain1.com but not on domain2.com with EXACTLY the same files and settings! 它在开发环境以及domain1.com上都可以完美运行,但在domain2.com上却不能完全相同的文件和设置!

/zeroclipboard/ZeroClipboard.js loads. /zeroclipboard/ZeroClipboard.js加载。

/zeroclipboard/ZeroClipboard.swf does NOT load! /zeroclipboard/ZeroClipboard.swf加载!

I tried everything but can't get it to work. 我尝试了一切,但无法正常工作。 I'm really confused why it work on domain1 but not on domain2?? 我真的很困惑为什么它不能在domain1上使用,而在domain2上不能使用?

How do I resolve this? 我该如何解决?

Many thanks for your help! 非常感谢您的帮助!

There are options for cross domain assets: 跨域资产有以下几种选择:

// SWF inbound scripting policy: page domains that the SWF should trust. (single string or array of strings)
  trustedDomains: [window.location.host],

See: https://github.com/zeroclipboard/zeroclipboard/blob/master/docs/instructions.md 参见: https : //github.com/zeroclipboard/zeroclipboard/blob/master/docs/instructions.md

Also: The current master branch (2.x) logs the cross domains to console if you set debug to true in config. 另外:如果您在配置中将debug设置为true,则当前的主分支(2.x)会将跨域记录到控制台。

I had some success using a cdn hosted version of the swf file. 我使用CDN托管版本的swf文件取得了一些成功。 But after making some edits this mysteriously stopped working locally but did work on my staging server. 但是,在进行了一些编辑之后,这神秘地停止了本地工作,但确实在我的登台服务器上工作了。

This is my config: 这是我的配置:

  ZeroClipboard.config({
    moviePath: '//cdnjs.cloudflare.com/ajax/libs/zeroclipboard/1.3.2/ZeroClipboard.swf',
    forceHandCursor: true,
    debug: true
  });

Also see this jsfiddle: 另请参阅此jsfiddle:
http://jsfiddle.net/rimian/45Nnv/ http://jsfiddle.net/rimian/45Nnv/

If you're still having trouble, you can log from the swf to console. 如果仍然遇到问题,可以从SWF登录到控制台。 For this, you need to be able to compile the flash, from zeroclipboard source into a swf using grunt mxmlc . 为此,您需要能够使用grunt mxmlc将flash从零剪贴板源编译为swf。 Simply dispatch a log event in the action script (compile and copy it into your project) and respond to it in your js: 只需在操作脚本中调度一个日志事件(编译并将其复制到您的项目中)并在js中对其进行响应:

For example, in ZeroClipboard.as : 例如,在ZeroClipboard.as

// constructor, setup event listeners and external interfaces
public function ZeroClipboard() {

  ...

  // Get the flashvars
  var flashvars:Object = LoaderInfo( this.root.loaderInfo ).parameters;

  dispatch("log", flashvars);

  ...

  }

Then in your js: 然后在您的js中:

zeroclipboard = new ZeroClipboard($('.mybuttons'))
zeroclipboard.on('log', function(client, args) { console.log('log:', args)});

If this file is located in the same directory as your web page, then it will work out of the box. 如果此文件与您的网页位于同一目录中,那么它将立即可用。 However, if the SWF file is hosted elsewhere, you need to set the URL like this (place this code after the script tag): 但是,如果SWF文件托管在其他位置,则需要这样设置URL(将此代码放置在script标签之后):

    ZeroClipboard.setMoviePath( 'http://YOURSERVER/path/ZeroClipboard.swf' );

To use the new Rich HTML feature available in Zero Clipboard 1.0.7, you must set the movie path to the new "ZeroClipboard10.swf" file, which is included in the 1.0.7 archive. 若要使用零剪贴板1.0.7中提供的新Rich HTML功能,必须将影片路径设置为新的“ ZeroClipboard10.swf”文件,该文件包含在1.0.7存档中。 Example: 例:

    ZeroClipboard.setMoviePath( 'ZeroClipboard10.swf' );

Or, in a custom location other than the current directory: 或者,在当前目录以外的其他自定义位置:

    ZeroClipboard.setMoviePath( 'http://YOURSERVER/path/ZeroClipboard10.swf' );

http://kenneth.kufluk.com/blog/2008/08/cross-domain-javascript-to-flash/ may help. http://kenneth.kufluk.com/blog/2008/08/cross-domain-javascript-to-flash/可能会有所帮助。 Also beware of subdomains, Flash can get confused. 也要提防子域,Flash可能会感到困惑。 Also use Flash debug player and Fiddler (or similar) to see what is going on. 还可以使用Flash调试播放器和Fiddler(或类似工具)来查看发生了什么。

I solved editing this line on ZeroClipboard.min.js 我解决了在ZeroClipboard.min.js上编辑此行的问题

return a+"ZeroClipboard.swf"

to: 至:

return "//YOUR/PATH/TO/ZeroClipboard.swf"

可能想尝试Fiddler来查看文件的请求/响应的外观。

设置moviePath和swfPath都对我有用。

ZeroClipboard.config({ moviePath: '/assets/ZeroClipboard.swf', swfPath: '/assets/ZeroClipboard.swf', debug: true });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM