javascript ZeroClipboard SWF 不加载

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3741691/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 02:06:01  来源:igfitidea点击:

ZeroClipboard SWF does not load

javascriptjqueryflashclipboardzeroclipboard

提问by eozzy

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. 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!

我正在使用流行的 ZeroClipboard 插件将内容复制到用户的剪贴板。它在开发环境和 domain1.com 上都能完美运行,但不能在 domain2.com 上使用完全相同的文件和设置!

/zeroclipboard/ZeroClipboard.jsloads.

/zeroclipboard/ZeroClipboard.js负载。

/zeroclipboard/ZeroClipboard.swfdoes 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??

我尝试了一切,但无法正常工作。我真的很困惑为什么它适用于域 1 而不适用于域 2??

How do I resolve this?

我该如何解决?

Many thanks for your help!

非常感谢您的帮助!

采纳答案by Tomas Voracek

http://kenneth.kufluk.com/blog/2008/08/cross-domain-javascript-to-flash/may help. Also beware of subdomains, Flash can get confused. Also use Flash debug player and Fiddler (or similar) to see what is going on.

http://kenneth.kufluk.com/blog/2008/08/cross-domain-javascript-to-flash/可能会有所帮助。还要注意子域,Flash 可能会混淆。还可以使用 Flash 调试播放器和 Fiddler(或类似的)来查看发生了什么。

回答by daidai

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(将此代码放在脚本标记之后):

    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. Example:

要使用零剪贴板 1.0.7 中可用的新 Rich HTML 功能,您必须将影片路径设置为新的“ZeroClipboard10.swf”文件,该文件包含在 1.0.7 存档中。例子:

    ZeroClipboard.setMoviePath( 'ZeroClipboard10.swf' );

Or, in a custom location other than the current directory:

或者,在当前目录以外的自定义位置:

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

回答by Rimian

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,当前的 master 分支 (2.x) 会将跨域记录到控制台。

I had some success using a cdn hosted version of the swf file. But after making some edits this mysteriously stopped working locally but did work on my staging server.

我使用 swf 文件的 cdn 托管版本取得了一些成功。但是在进行了一些编辑后,这神秘地在本地停止了工作,但在我的登台服务器上工作了。

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:
http://jsfiddle.net/rimian/45Nnv/

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

If you're still having trouble, you can log from the swf to console. For this, you need to be able to compile the flash, from zeroclipboard sourceinto a swf using grunt mxmlc. Simply dispatch a log event in the action script (compile and copy it into your project) and respond to it in your js:

如果您仍然遇到问题,您可以从 swf 登录到控制台。对于这一点,你需要能够编译闪光灯,从zeroclipboard源到使用SWF grunt mxmlc。只需在操作脚本中发送一个日志事件(编译并将其复制到您的项目中)并在您的 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)});

回答by Herlon Aguiar

I solved editing this line on ZeroClipboard.min.js

我解决了在 ZeroClipboard.min.js 上编辑这一行

return a+"ZeroClipboard.swf"

to:

到:

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

回答by Freddy

Setting both moviePath and swfPath worked for me.

设置 moviePath 和 swfPath 对我有用。

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

回答by JoshNaro

Might want to try Fiddlerto see exactly what the request/response looks like for the file.

可能想尝试使用Fiddler来准确查看文件的请求/响应是什么样的。