Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
209 views
in Technique[技术] by (71.8m points)

javascript - How does Financial Times add a disclaimer when pasting text?

Here is an example of what happens when pasting text from Financial Times, the top paragraph is added.

Thanks in advance!

Example:

Please respect FT.com's ts&cs and copyright policy which allow you to: share links; copy content for >personal use; & redistribute limited extracts. Email ftsales.support@ft.com to buy additional rights >or use this link to reference the article - http://www.ft.com/cms/s/0/792f1aec->9600-11e0-8256-00144feab49a.html#ixzz1PFrYZiD0

Goldman Sachs gave a paid internship to a top Libyan official’s relative while the bank was carrying >out lossmaking trades on behalf of the country’s sovereign wealth fund, the Financial Times has learnt.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As already previously mentioned, modifying the clipboard data is either restricted to specific browsers or requires the user to grant access to modifying the clipboard. A work around to this you could

  1. Add an event handler to the oncopy event
  2. Find the selection
  3. Prepend/append content to the content
  4. Modify the selection range to include the appended/prepended content
  5. Wait for the copy action to push through
  6. Remove the appended/prepended content

I fiddled about with this method and created a plugin which does just that. Still a preliminary version and only tested on FF4/Chrome 11/IE8 so far (and IE definetly needs to have some more work done). Some of the nice things you can do with this method is that you could easily for example wrap forum post quotes in [quote=USER]content[/quote] and assign the user based on which post is copied. By default, the script always selects the DOM styling, but not the actual HTML, so if you for example copy bold content, it would be bold if pasted into a rich text editor, but just text if used in text only editors (removing the html tags).

Prepending content is significantly easier with this method, compared to appending, in which case I still am not sure whether it is fully functional. For IE, you could directly modify the clipboard, but there are some issues for example when selecting the whole page, or if you want to toggle the rich copy content. Haven't had the chance to do any further browser testing, but this appears to be at least a working solution for newer browsers.

Example: http://hertzen.com/experiments/jquery.plugin.clipboard/

Another example: http://hertzen.com/experiments/jquery.plugin.clipboard/thread.html

Source code: https://github.com/niklasvh/jquery.plugin.clipboard


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...