从网站复制/粘贴时编辑剪贴板数据 [英] Editing clipboard data when copying/pasting from a website

查看:124
本文介绍了从网站复制/粘贴时编辑剪贴板数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在看到一些网站,如果你突出文章的文字,复制它,然后粘贴,他们可以添加更多的文字。

I have seen a few sites now where if you highlight text of an article, copy it, and then paste in they can add more text to it.

尝试复制并粘贴 http://belfasttelegraph.co.uk/ 上的文章中的一段文字我明白我的意思 - 他们在粘贴文本中添加了原始文章的链接。

Try copying and pasting a section of text from an article at http://belfasttelegraph.co.uk/ and you'll see what I mean - they add a link to the original article in the pasted text.

这是怎么做到的?我假设有一些javascript在这里工作

How is this done? I'm assuming there is some javascript at work here

推荐答案

这是一个很好的效果,你可以看到被解雇的脚本使用Firebug进行复制(在Firefox中)。

This is a good effect, you can see the scripting that is fired on copy using Firebug (in Firefox).

启动Firebug并加载页面,选择clear(因为页面使用了很多ajax,很快就有100个请求) 。然后选择全部选项卡并尝试复制。您将看到1x1像素图像的请求,但如果您按+按钮查看详细信息,您将在'params'选项卡中看到此GET请求将您请求的文本作为'content'参数传递,将用于操纵剪贴板DOM的xpath信息:

Start up Firebug and load the page, choose clear (because the page uses a lot of ajax there are very quickly 100 requests). Then choose the 'All' tab and try to copy. You will see a request for a 1x1 pixel image but if you press on the + button to look at the details, you will see in the 'params' tab that this GET request passes your requested text as the 'content' parameter, with some xpath information that will be used to manipulate the clipboard DOM:

start_node_xpath    /HTML/BODY[@id='belfast']/DIV[@id='root']/DIV[@id='content']/DIV[@id='mainColumn']/DIV[@id='article']/DIV[5]/P[39]/text()

end_node_xpath  /HTML/BODY[@id='belfast']/DIV[@id='root']/DIV[@id='content']/DIV[@id='mainColumn']/DIV[@id='article']/DIV[5]/P[41]/text()

正如@Crimson指出的那样,有一些方法可以操纵剪贴板,喜欢zeroclipboard 使用Flash和图像。

As @Crimson pointed out there are methods to manipulate the clipboard, like zeroclipboard which use Flash and an image.

我认为通过使用图像获取请求来更改剪贴板是如何完成该技术的。

I reckon that is how the technique is done by using the image get request to change the clipboard.

这篇关于从网站复制/粘贴时编辑剪贴板数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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