如何在jQuery中实际使用ZeroClipboard? [英] How to actually use ZeroClipboard in jQuery?

查看:96
本文介绍了如何在jQuery中实际使用ZeroClipboard?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我就是不明白这一点. ZeroClipboard应该如何工作?为什么需要在复制的文本上移动Flash元素?

I just can't get this thing. How is ZeroClipboard supposed to work? Why does it need to move the flash-element over the copied text?

我已阅读以下内容: http://code.google.com/p/zeroclipboard/wiki/说明

有人可以给我一个简短的摘要,当用户单击链接时,可以将变量中的文本复制到用户剪贴板.这有可能吗?我不在乎,如果它不能在所有浏览器(例如IE6)上都无法正常工作.

Can someone provide me a short snippet, which makes it possible to copy a text in variable to users clipboard, when user clicks a link. Is this even possible? I don't care, if it doesn't work on all browsers (IE6 for example).

我正在使用jQuery.

I'm using jQuery.

推荐答案

您链接到的页面上给出的最小示例"代码(

The "minimal example" code given on the page you link to (http://code.google.com/p/zeroclipboard/wiki/Instructions#Minimal_Example) appears to be what you want. I've copied it here and altered it to demonstrate putting text into a variable and then copying that text to the clipboard, since that's what you're interested in. Note that, in real life, what you'd presumably want to do is call the clip.setText() part within some function, since you might not know, at the point when the page is first loaded, what text you want to copy.

<html>
<body>
        <script type="text/javascript" src="ZeroClipboard.js"></script>

        <div id="d_clip_button" style="border:1px solid black; padding:20px;">Copy To Clipboard</div>

        <script language="JavaScript">
                var clip = new ZeroClipboard.Client();
                var myTextToCopy = "Hi, this is the text to copy!";
                clip.setText( myTextToCopy );
                clip.glue( 'd_clip_button' );
        </script>
</body>
</html>

flash元素不必位于复制的文本上方";需要将其粘合"到您希望用户操作的任何DOM元素上-最有可能是要单击的按钮.原因是Javascript无法访问剪贴板,因此您需要使用Flash.但是Flash只能响应用户的点击而在用户的计算机上运行-因此,您可以通过使用户在Flash上​​隐藏HTML元素来诱骗"用户点击Flash.

The flash element doesn't need to be "over the copied text"; it needs to be "glued" to whatever DOM element you want your user to manipulate -- most likely a button to click. The reason is that Javascript doesn't have access to the clipboard, so you need to use Flash instead. But Flash can only operate on the user's machine in response to a user's click -- so you "trick" the user into clicking on the Flash by making it an invisible overlay over an HTML element.

我会注意到,虽然复制到用户剪贴板的特定示例可能是无害的,但这种方法使我感到困扰,因为不难想像隐藏的Flash元素在做更多恶意的事情.

I'll note that while the particular example of copying to the user's clipboard is probably benign, this approach troubles me, as it wouldn't be hard to imagine the hidden flash element doing more malicious thing.

这篇关于如何在jQuery中实际使用ZeroClipboard?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆