使用 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);
HTML:
<button class="embed-copy" id="copy-button" data-clipboard-text="some old copied text">Copy</button>
如何动态加载 ZeroClipboard 并成功触发'complete'
事件(将文本复制到剪贴板)?