ZeroClipboard是一个javascript + flash脚本,允许浏览器将文本放入剪贴板,它在所选元素上放置一个透明的闪存,当你点击它时你可以在剪贴板中插入文本,这没问题,但我想让它自动化。 Onload将一个字符串放在剪贴板中,以便用户能够将其粘贴到后面。一些代码 main.js
$('document').ready(function() {
ZeroClipboard.setMoviePath("http://url/to/ZeroClipboard.swf");
var clip=new ZeroClipboard.Client();
clip.on( 'load', function(client) {
clip.glue('#redirlink');
} );
});
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb" dir="ltr" >
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="main.js"></script>
<title>TEST</title>
</head>
<body>
<div >
<a id="redirlink" data-clipboard-text="abcd" href="http://alabala.com" >Click HERE</a>
</div>
</body>
</html>
好了,现在的问题是如何在zeroClipboard上模拟点击事件?我试过,$('#obkect_id").click();
它不起作用(事件触发,但它对剪贴板没有影响,但是当我用鼠标点击时,它可以工作)。有什么办法可以实现吗?
答案 0 :(得分:4)
最新版本的ZeroClipboard已经废除了Client()。因此代码也有所改变。 从Github这里下载最新版本
然后再说你想在页面/元素加载时更新/放置一些字符串。说点击具有id'#id'的'元素',剪贴板需要加载一些文本
<script>
var str = 'Some text';
$('element').attr('data-clipboard-text','str');
ZeroClipboard.setDefaults({moviePath:'http://...../ZeroClipboard.swf'});
var clip = new ZeroClipboard($('#id'));
clip.on('complete',function(client, args){
alert('Copied');
});
</script>
希望这有帮助
答案 1 :(得分:1)
很遗憾,您无法模拟Flash对象上的点击,并将其设置在剪贴板http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/desktop/Clipboard.html#中。这是Adobe的安全预防措施。