使用ZeroClipboard --成功地调用了'load'回调,但是单击'copy-button'元素不会引发'complete'回调。
JS
var script = document.createElement('script'), loaded;
script.setAttribute('src', "/static/ZeroClipboard.js");
script.onreadystatechange = script.onload = function() {
if (!loaded) {
console.log("Executing ZeroClipboard load callback");
var clip = new ZeroClipboard(
document.getElementById('copy-button'),
{moviePath: '/static/ZeroClipboard.swf',
allowScriptAccess: "always"} // allow cross-domain swf load
);
clip.on('complete', function(client, args) {
console.log('ZeroClipboard: copied text to clipboard: ' + args.text );
});
clip.on('load', function(client) {
console.log('ZeroClipboard: clip loaded');
});
}
loaded = true;
};
document.getElementsByTagName('head')[0].appendChild(script);<button class="embed-copy" id="copy-button" data-clipboard-text="some old copied text">Copy</button>如何动态加载ZeroClipboard并成功触发'complete'事件(将文本复制到剪贴板)?
发布于 2013-06-25 14:38:04
以上代码中没有任何错误。事实证明,ZeroClipboard创建的用于捕获点击的不可见的swf是成功创建的,但在错误的位置创建。这是因为按钮是通过css转换定位的,是一个ZeroClipboard本身的错误。希望这一拉请求将很快合并。
现在,我只是手动将贴片 (8行左右)应用于我正在使用的ZeroClipboard版本。
作为参考,这会影响到ZeroClipboard v1.2.0-beta.1。
https://stackoverflow.com/questions/17282854
复制相似问题