【发布时间】:2015-07-24 05:11:01
【问题描述】:
按照此处的示例尝试让 Zeroclipboard.js 在 Meteor 应用程序中工作:http://www.thewebflash.com/2014/10/copy-to-clipboard-cross-browser-using.html。
我在客户端文件夹中有最新的 ZeroClipboard.js 和 ZeroClipboard.swf。
在我的模板中,我有:
<template name="listPage">
<!-- some other markups -->
<input type="text" id="input1" />
<button type="button" id="btn-copy1" class="btn-copy">Copy to Clipboard</button>
<span class="span-message"></span>
</template>
与事件配对:
Template.listPage.events({
'click .btn-copy': function(e) {
e.preventDefault();
var client = new ZeroClipboard($('.btn-copy'));
client.on('ready', function(event) {
client.on('copy', function(event) {
// `this` === `client`
// `event.target` === the element that was clicked
// Get the text content of <input> or <textarea> that comes immediately before the clicked button
var $prevEle = $(event.target).prev();
var text = $prevEle.is('textarea') ? $prevEle.val().replace(/\n/g, '\r\n') : $prevEle.val();
// If value of `text` is not empty, set the data to clipboard
if (text) {
event.clipboardData.setData('text/plain', text);
}
});
client.on('aftercopy', function(event) {
// Check if copied text is not empty
if (event.data["text/plain"]) {
// Call something on successful copying
$(event.target).next().stop().css('opacity', 1).text('Copied!').fadeIn(30).fadeOut(1000);
}
});
});
client.on('error', function(event) {
ZeroClipboard.destroy();
});
}
});
我也试过https://github.com/zeroclipboard/zeroclipboard上的简单例子
不知道我做错了什么。非常感谢您的帮助。
【问题讨论】:
-
由于浏览器和 Flash 安全限制,这种剪贴板注入只有在用户点击不可见的 Flash 影片时才会发生。来自 JavaScript 的模拟点击事件是不够的,因为这会导致剪贴板中毒。
-
github上的msg,你搞定了吗,那里有补丁
-
所以我可能没有点击不可见的 Flash 电影,因此没有复制任何内容。
标签: javascript jquery meteor