Live data from Hacker News

How to control what is copy-pasted to and from the clipboard in the browser

taye.me

21–30 of 40 posts

Re: How to control what is copy-pasted to and from the clipboard in the browser

#22
Please, please don't do this. By doing it you break UI conventions I can rely on everywhere else, and introduce yet another thing that's not quite going to work right in some combination of platform and browser.

You probably don't have the budget to make sure this works properly as you intend it everywhere it's accessible, and by introducing it you're actively making your site, and by extension my experience, less reliable and less predictable.

Re: How to control what is copy-pasted to and from the clipboard in the browser

#23
post #15

Earlier quoted context omitted.

In what world is it "fair" for you to alter the behavior of what I expect to happen just because some people find it "easy" to fix the way you broke it?

Not all copying is fair. Many copyrighted content is copied without the author's permission and used in non-fair-use contexts. Therefore it seems reasonable for the copyright holder to alter the behavior of the copy function and append the URL to the copied text. But I say that because I'm a reasonable person. If you feel entitled to being able to copy everything as is, then I suppose you won't like it being altered.

That is not a reasonable stance. What you're saying is that the site owner is entitled to pre-judge any copy and paste as inherently unfair, and break everyone's experience as a result. That's not a judgement they should be able to make, and it's not a right they have.

Re: How to control what is copy-pasted to and from the clipboard in the browser

#24

Earlier quoted context omitted.

Not all copying is fair. Many copyrighted content is copied without the author's permission and used in non-fair-use contexts. Therefore it seems reasonable for the copyright holder to alter the behavior of the copy function and append the URL to the copied text. But I say that because I'm a reasonable person. If you feel entitled to being able to copy everything as is, then I suppose you won't like it being altered.

That is not a reasonable stance. What you're saying is that the site owner is entitled to pre-judge any copy and paste as inherently unfair, and break everyone's experience as a result. That's not a judgement they should be able to make, and it's not a right they have.

>>and break everyone's experience

Come on. Appending a URL to the copied text doesn't break anyone's experience. It's a very tiny inconvenience at best.

As for them pre-judging any copy and paste as inherently unfair, most people on the Internet copy and steal things without giving credit. Appending a URL to a chunk of copied text is a way of nudging them to cite the material. As for fair-use folks, I see it as helpful. I always cite material I copy from elsewhere manually, but now the script does it for me. In either case, it's a win.

Re: How to control what is copy-pasted to and from the clipboard in the browser

#25
The actual way to control what is copy/pasted is to use the `oncopy` and `onpaste` events and using the clipboard API[0]. This obviously relies on the browser providing sufficient clipboard access, but that's getting there[1]

Bonus: you can get (on paste) and set (on cut and copy) data in multiple file formats. And obviously you can pre-process pasted data before injecting it in the system.

[0] http://www.w3.org/TR/clipboard-apis/

[1] http://caniuse.com/clipboard

Re: How to control what is copy-pasted to and from the clipboard in the browser

#26

>>Try right-clicking here to see this working I right clicked on your "intercepting element," inspected with firebug, and deleted the input node. Then I could copy and paste as I desired. Firefox. 10 seconds? My point is, we have many better things to spend our time on as developers than trying to control our user's access to the same information we're providing them. This not a reproach to taye, but to the bosses th…

In chrome I can just right click the text, keep right mouse held down while I use left mouse to highlight the text I want and then lift right mouse while hovered over my newly highlighted text and select copy. This method while overkill is easily circumvented in the provided example, without even killing js or using developer tools, it could possibly be fixed with a larger covering item, but really if you don't want people copying your text, use a library to render it as an image.

Re: How to control what is copy-pasted to and from the clipboard in the browser

#27

Please, please don't do this. By doing it you break UI conventions I can rely on everywhere else, and introduce yet another thing that's not quite going to work right in some combination of platform and browser. You probably don't have the budget to make sure this works properly as you intend it everywhere it's accessible, and by introducing it you're actively making your site, and by extension my experience, less re…

There is one case where I really do appreciate manipulating copy-paste: selecting multiple cells in a table.

Excel ends up populating the plaintext as well as the HTML paste buffers. The plaintext buffer holds TSV output and the HTML buffer holds the full HTML. The HTML is the only way to distinguish between the two cells

    |"foo|bar"|
and the single cell

    |"foo\tbar"| (using some CHAR magic in excel to generate the tab character)
my short spiel: http://blog.sheetjs.com/post/66908170192/the-magic-behind-ex...

Re: How to control what is copy-pasted to and from the clipboard in the browser

#28

Please, please don't do this. By doing it you break UI conventions I can rely on everywhere else, and introduce yet another thing that's not quite going to work right in some combination of platform and browser. You probably don't have the budget to make sure this works properly as you intend it everywhere it's accessible, and by introducing it you're actively making your site, and by extension my experience, less re…

What if your site is a graphic editing web app using a renderer? By convention users should be able to copy and paste graphical objects created within the app as well as paste text or images copied from elsewhere.

If you use keyboard short-cuts in your UI to copy into your app's memory but not the system clipboard then you have no way to know whether the data the user wants to paste was copied from your app or somewhere else. If you only use the system clipboard and inform the user that copy/pasting is done with right-click or key-combos and not the browser's "Edit" menu, you can handle copy-pasting predictably.

This was the most reliable method I could think of. Yes the browser's "Edit" menu is a problem and there's no way to get around that.

Re: How to control what is copy-pasted to and from the clipboard in the browser

#29

More important, how do I keep a site from changing what I copy / paste, because this is the crappiest UI change a site can make. I am rather sick of copying a phrase and getting a huge site advertisement and url attached.

how do I keep a site from changing what I copy / paste

1. Disable Javascript. I browse with NoScript / Scriptsafe plugs installed, and disable JS by default. This defeats the demo in the article (I actually had to enable JS to break my copy/paste).

2. Use a console-mode browser and/or curl the source and grab what you want from it (though I've found sites which break console tools).

Better: enter domains which employ such tactics in your /etc/hosts file as 0.0.0.0.

Re: How to control what is copy-pasted to and from the clipboard in the browser

#30
post #6

More important, how do I keep a site from changing what I copy / paste, because this is the crappiest UI change a site can make. I am rather sick of copying a phrase and getting a huge site advertisement and url attached.

I've never actually noticed any site doing that to me as I usually browse with NoScript. I wrote that post with the intention of using the solution in apps to copy/paste app data in plain text - eg. selecting multiple objects in a drawing app and copying them as a JSON string. I guess NoScript/Ghostery/AdBlock Plus could be considered solutions to your problem.

> I've never actually noticed any site doing that to me as I usually browse with NoScript.

Not necessarily a solution, as you can do it with css only. For example, people can put a 0-sized snippet at the end of the text, and then pad with some non-copyable text, so you select ABC, end up copying AB.

IIRC twitter does this for urls (think "http://oo.com…").

Post reply on HN