简体   繁体   English

ZeroClipboard:swf加载但无法正常工作

[英]ZeroClipboard: swf loaded, but not working

ZeroClipboard doesn't work and it doesn't throw any errors (javascript console). ZeroClipboard不起作用,它不会抛出任何错误(javascript控制台)。

The website is hosted on a HTTPS webserver running on localhost. 该网站托管在localhost上运行的HTTPS网络服务器上。 Both the website and the SWF are served over HTTPS by the same server. 网站和SWF都由同一服务器通过HTTPS提供。

The SWF is loaded and positioned correctly over the button (with ID: testButton). SWF加载并正确定位在按钮上(ID:testButton)。 When right-clicking on the button, the flash context menu (About Adobe Flash Player 11.7...) is shown. 右键单击该按钮时,将显示Flash上​​下文菜单(关于Adobe Flash Player 11.7 ...)。

However, none of the events, not even "load", gets fired. 但是,没有任何事件,甚至没有“加载”,都会被解雇。

I am working on this problem for 我正在研究这个问题 two days 两天 months now and i can't find a solution. 现在几个月,我找不到解决方案。

Additional info: 附加信息:

  • ZeroClipboard version: v1.1.7, also tried v1.2.0-beta.3, edit: This also happens with v1.3.1 ZeroClipboard版本:v1.1.7,也尝试过v1.2.0-beta.3,编辑:这也适用于v1.3.1
  • Browser: Chromium 28 on Mac OSX 浏览器:Mac OSX上的Chromium 28
  • Official test website is working 官方测试网站正在运行

Here is my code: 这是我的代码:

var clip = new ZeroClipboard(document.getElementById("testButton"), {
    moviePath: "media/zeroclipboard.swf"
});
clip.on("dataRequested", function(client, args) {
    client.setText("Copy me!");
});
clip.on("load", function(client) {
    alert("movie is loaded");
});
clip.on("complete", function(client, args) {
    alert("Copied text to clipboard: " + args.text);
});
clip.on("mouseover", function(client) {
    alert("mouse over");
});
clip.on("mouseout", function(client) {
    alert("mouse out");
});
clip.on("mousedown", function(client) {
    alert("mouse down");
});
clip.on("mouseup", function(client) {
    alert("mouse up");
});

After months I finally found a solution: 几个月后我终于找到了解决方案:

ZeroClipboard doesn't work out-of-the-box in CommonJS environments in the browser, even it says it does. ZeroClipboard在浏览器的CommonJS环境中不能开箱即用,即便如此。

The fix for that is assigning the module scope variable (eg ZeroClipboard) to the global window object: 解决方法是将模块范围变量(例如ZeroClipboard)分配给全局窗口对象:

ZeroClipboard = require("zeroclipboard");
window.ZeroClipboard = ZeroClipboard;

I created a bug report on this: https://github.com/zeroclipboard/zeroclipboard/issues/332 我创建了一个错误报告: https//github.com/zeroclipboard/zeroclipboard/issues/332

I'm not sure if this would help~ but have you tried changing your moviePath a little bit? 我不确定这是否会有所帮助〜但你有没有试过改变你的moviePath? Like this: 像这样:

{moviePath:"//YOURSERVER/path/ZeroClipboard.swf"}

I was trying to use ZeroCLipboard in the whole month and most of the time I fail because I got the path wrong in one way or another... 我整个月都试图使用ZeroCLipboard,而且大部分时间我都失败了,因为我以这种或那种方式弄错了路径......

Good luck anyways~ 祝你好运〜

如果准确提取项目,.SWF文件位于:

moviePath: "../zeroclipboard.swf"

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

return a+"ZeroClipboard.swf"

to: 至:

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

Would just like to point out for anybody else who finds this question first: ZeroClipboard does not work when looking at the file locally ie file://path/index.html . 我想首先指出找到这个问题的其他人:ZeroClipboard在本地查看文件时不起作用,即file://path/index.html This is because of Adobe's security policies blocking the file:// protocol. 这是因为Adobe的安全策略阻止了file://协议。

https://stackoverflow.com/a/9450359/710377 https://stackoverflow.com/a/9450359/710377

If you're already using Node.js at all (even just for the package manager) you can spin up a basic web server on the command line to test ZeroClipboard with npm install http-server -g and http-server /path/ (assuming that npm stuff is already on your path). 如果您已经在使用Node.js(甚至只是用于包管理器),您可以在命令行上启动基本Web服务器以使用npm install http-server -ghttp-server /path/来测试ZeroClipboard。假设npm的东西已经在你的路径上)。

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

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