使用商标将JavaScript复制到剪贴板

I published a post a year ago detailing how you can copy to the clipboard using JavaScript.  The post was very popular and why would it be?  Copying content from a webpage without needing to use the default browser functions is awesome.  One trend I've seen recently is that when the use copies content from a given post, the copy function (Zero Clipboard, in this example) appends the page title, a link, and a special message telling the recipient to view the post.  Here's how to do it.

我一年前发表了一篇文章,详细介绍了如何使用JavaScript复制到剪贴板 。 该帖子非常受欢迎,为什么会这样? 从网页复制内容而无需使用默认浏览器功能真是棒极了。 我最近看到的一种趋势是,当用户从给定帖子中复制内容时,复制功能(在此示例中为“零剪贴板”)会附加页面标题,链接和一条特殊消息,告诉收件人查看该帖子。 这是操作方法。

JavaScript (The JavaScript)

Assuming the user is using ZeroClipboard functionality:

假设用户正在使用ZeroClipboard功能:


//set path
ZeroClipboard.setMoviePath('https://davidwalsh.name/demo/ZeroClipboard.swf');
//create client
var clip = new ZeroClipboard.Client();
//event
clip.addEventListener('mousedown',function() {
	clip.setText(document.getElementById('box-content').value + ".\n\nRead " + window.title + " at " + window.location + " to learn more!");
});
//glue it to the button
clip.glue('copy');


Appending the special message to the given text is done with basic JavaScript string concatenation of available window properties.

将特殊消息附加到给定的文本是通过可用窗口属性的基本JavaScript字符串串联完成的。

This post is more about the idea than it is the execution.  This type of marketing is good for newspaper-style websites that host thousands of posts and want to give themselves credit for the content that's been copied.

这篇文章更多地是关于这个想法,而不是执行。 这种营销方式对于拥有数千个帖子并且希望对自己复制的内容功不可没的报纸式网站很有用。

翻译自: https://davidwalsh.name/javascript-clipboard

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值