JavaScript to Manipulate Copied Text
I copied come text from a The Huffington Post article and fo开发者_如何学JAVAund that the web site had somehow snuck a citation onto my clipboard:
The text I had selected. Blah. Blah. Blah.
Read more at: http://www.huffingtonpost.com/...
How did they do that?
The code that does this is in http://www.huffingtonpost.com/include/lib/copy_paste.js?v=1.02
It looks like on mouse-up events they check to see if any text is selected, and if it is then they insert an invisible div containing the citation inside of the selection.
http://snipplr.com/view/6450/javascript-copy-text-to-clipborad/ contains a function on how to copy text to the clipboard.
It's probably done on the copy event: gets the currently selected text and adds the "Read more... " then calls a function similar to the one linked above.
精彩评论