
Clipboard.js: Modern Copy to Clipboard - jellekralt
https://github.com/zenorocha/clipboard.js
======
david-given
Text field autoselection and programs being 'helpful' by copying things to the
clipboards is one of the banes of my life. I wish there was a way to just
disable all this, globally. If I want something selected, I'll select it
myself, thanks.

My problem with text field autoselection is that it's wrecking my muscle
memory of how to interact with text fields. My reflexes know that a single
click places the cursor, a double click selects a word, and a triple click
selects a line... except when the text field has autoselect turned on, which I
can only find out _after_ I've committed to the action. And they all behave
slightly differently.

Example interaction:

\- click on text field to place cursor.

\- text field autoselects. I swear.

\- click again to place cursor.

\- hasn't been long enough since the last click, which means it's interpreted
as a double click.

\- text field selects word. I swear.

At this point I'll either force myself to wait for a second or so, to make the
interaction time out, and then click _again_ , or else I'll be too impatient
and the madness continues as my third click is interpreted as a triple-click.

Seriously, wish there was a way to make this all stop. If I want my text
fields selected, I'll do it myself, thanks.

~~~
pdkl95
If there was a Firefox extension that simply disabled 100% of the ability to
control or influence the selection, I'd install it in a second.

Manipulating the selection is probably a specific case of the larger problem
of terrible, incomplete reimplementations of UI that already exists. This
inevitably ends up demonstrating the exact gap between what user environment
is, and what the webpage author believes it _ought_ to be.

~~~
myfonj
From a quick glance it seems quite possible to make such extension: simple
dark prototype crippling for inputs and textareas like

    
    
        Selection.prototype.addRange = HTMLTextAreaElement.prototype.select = HTMLInputElement.prototype.select = function(){ console.info(this,' arificial selection disabled, sorry.') }
    

If you use some userscript manager, try it with
[https://greasyfork.org/en/scripts/12762-disable-arificial-
se...](https://greasyfork.org/en/scripts/12762-disable-arificial-selections)

~~~
nacs
Hate to be that guy but just wanted to point out the typo in the console
message/userscript title:

"arificial" should be "artificial" (missing 't').

~~~
myfonj
Hanks for pointing out, good catch! Fixed in userscript, also updated it a
bit. Not able to fix it here. Seems like quite frequent mistype BTW :]

------
hayksaakian
I was thinking -- why isn't this more common?

Then I read the bottom of the readme, and noticed safari was holding back
webdev once again.

I've been casually following this for the last 5 years and it seems almost too
convenient that safari is regularly behind on mission critical features.

~~~
jacobolus
Funny. I find Safari leaps ahead of Firefox, and even further ahead of Chrome,
when it comes to browser performance (CPU use, memory footprint, and
especially battery life), with snappier scrolling and animations and fewer
weird graphical glitches or mouse/keyboard interaction bugs. For my own
browsing habits, Firefox is _very_ sluggish, and Chrome is completely
unusable: it just can’t handle the load and brings my whole computer to a
crawl. The Safari user interface also feels much more platform-native and
predictable (though it has unfortunately copied several Chrome UI elements in
the last few years, which I think make the basic UI worse than ~5 years ago),
and I don’t constantly feel like someone is trying to gather and analyze my
keystrokes or sell me out to advertisers. (I don’t have a Windows machine, so
I couldn’t tell you what IE is like these days.)

Maybe there’s just a focus on different things between vendors: Google has
tons of 20%-time engineers pushing new half-baked features in every direction
(yes this is a bit of a caricature), while Apple is taking a more measured
approach with a focus on performance and reliability.

~~~
Oletros
> For my own browsing habits, Firefox is very sluggish, and Chrome is
> completely unusable: it just can’t handle the load and brings my whole
> computer to a crawl.

Any example of those pages that brings the computer to a crawl?

~~~
jacobolus
It’s not any particular page that makes Chrome die. It’s opening more than 30
at a time. (I typically have anywhere from 50–200 browser tabs open at once.)

~~~
darrhiggs
Do you use task manager (Hotdog menu > More tools) to kill tabs that you are
not currently using? Also chrome 46 looks to be getting much better[0];
although I have also noticed a sizeable improvement with 45.

[0] [http://thenextweb.com/apps/2015/08/20/chrome-is-finally-
gett...](http://thenextweb.com/apps/2015/08/20/chrome-is-finally-getting-
faster-on-mac/)

------
eponeponepon
What does this do that OS native clipboards don't? Serious question - are
there platforms I'm unaware of where the functionality doesn't exist but a web
browser does? Seems unlikely to me, but I might be wrong.

~~~
bshimmin
It gives you a button you can click to select a predetermined piece of text
and add it to your clipboard. That's it. This is handy from a usability
perspective in some circumstances.

------
outsidetheparty
The documentation is a bit coy about this, but the usual purpose for this sort
of library is so you can modify the copied text before it hits the user's
clipboard, to insert an advertisement or copyright notice. (See the 'data-
clipboard-text' attribute.)

So, for evil. Safari not supporting execCommand copy and paste is a _good_
thing for users.

(This claims to work in all major browsers except Safari, but I'm see the same
fallback when I try it in Firefox, on OS X at least -- it shows the key
combination in a popup instead of actually copying or cutting the text as it
does in Chrome.)

------
Buetol
I needed a simple "click to copy some data" so I made this simple function:
[https://gist.github.com/mdamien/a0f2bd91750a2d45c8ab](https://gist.github.com/mdamien/a0f2bd91750a2d45c8ab)

I feel like the need for a whole library here is a bit overkill if you have a
"simple" usage.

------
deejbee
Does it copy/paste image data too? My brief look at the docs doesn't seem to
mention it but it would be ace if it did...

------
zserge
Glad to see new libraries for the new clipboard API! I was recently making a
color picker website that would not use flash for copying color values
([http://0xrgb.com](http://0xrgb.com)) and I was really missing a library like
this. Anyway thanks, I hope it will replace zeroclipboard very soon!

------
marwann
I'd love to see the ability to paste without using the keyboard too. Is that
something possible/on the roadmap?

~~~
ludwik
I don't think so. Ability to access information in user's system clipboard
seems like a huge security and privacy issue.

------
welder
Just switched [https://wakatime.com/](https://wakatime.com/) to this
yesterday... it's so much better than ZeroClipboard!

1\. ZeroClipboard has issues with Bootstrap tooltips on the copy button

2\. This doesn't depend on Flash!

3\. Gracefully downgrades to a "Press Ctrl+C to copy" message for Safari

~~~
stephenr
The irony of telling safari users to "press control c" is ridiculous.

Safari on iOS doesn't have a control key and on OS X copy is "Command-C"

But honestly the idea that someone can't select text and copy it themselves
(and thus need this helper) is a stretch of reality anyway so why am I
surprised that it doesn't reflect reality in its "fallback" either..

~~~
apinstein
It's not a stretch. If you have a product that "real" people use and phone
number for customer support, you will quickly learn the value of a copy-to-
clipboard feature.

People cannot even successfully select complete URLs at an alarming frequency.

~~~
stephenr
> If you have a product that "real" people use and phone number for customer
> support, you will quickly learn the value of a copy-to-clipboard feature

 _Real_ people have being using _regular_ select + copy operations on their
device of choice, for literally decades.

I honestly don't understand why every web app developer assumes that their
user base is full of people that just picked up a device with a browser and
have never used it before.

~~~
mordocai
We don't assume anything. We take calls from customers where they can't figure
out how to copy and paste. We take calls where customers don't even know what
a browser is, or a web page, or in some extreme cases how to select a textbox
and type in it.

Just because your customers (assuming you do web dev) can figure things out
doesn't mean everyones' can.

------
elwell
Started project 13 days ago and has 4k+ GitHub Stars

"This might come in handy; better star it."

------
mavster
Okay, who pressed the star button?
[https://github.com/zenorocha/clipboard.js/issues/56](https://github.com/zenorocha/clipboard.js/issues/56)

------
Rifu
And for the truly adventurous, there's the html5 clipboard api.

~~~
masklinn
Isn't the "problem" of the HTML5 clipboard API that you can only access the
clipboard during clipboard events, so you can't put stuff in the clipboard on
a button click, which is exactly the user-case for this library?

~~~
Rifu
This is very true, though I was mostly commenting on the "Modern copy to
clipboard" description.

------
lkjasdoiuqwe
The whole point of flash-based clipboard libraries are to support legacy
browsers. This attempt at removing those falls flat and does not support ie8,
sigh...

~~~
nevi-me
IE8 is holding the rest of us back. Reality is that most usage of IE8 comes
from corporate users who are stuck on such IE8. We can't keep supporting
legacy browsers forever. The solution that has been working is to warn the
user that their browser is not officially supported, and that things will
break.

One of the banks that I consult with allow users to install the corporately
limited version of Chrome, it's sometimes 10 or more versions behind latest
stable, but it's better than IE8.

Bootstrap, Font-Awesome, jQuery are dropping IEx because it's a burden to
maintain that for a small subset of users. We should all do the same.

~~~
Killswitch
I personally follow Google in what I support unless the project I am working
on is specifically for older browsers.

My idea is if Google who owns a huge market share of the web can drop it, it's
safe to say so can I.

------
raverbashing
Another trick using clipboards (in Mac OS X): use pbcopy/pbpaste to copy and
paste to clipboard

------
kzhahou
So modern!

Isn't any library released today, which improves on libraries from yesterday,
by definition "modern"?

Whenever I hear "modern" I just picture the developer thumbing his nose at the
old fuddy-duddies who don't know how to code and spew out garbage. Yeah yeah,
I get it -- the older stuff sucks. But maybe I'm imagining it. If people here
tell me that the word "modern" is truly free of derision, I'm open to that
viewpoint.

~~~
bshimmin
Well, in this case it relies on the Selection API which is currently still a
Working Draft - that sounds quite "modern" to me. It also eschews an older
technology (Flash) in favour of newer ones, so that also seems to be a
forgivable usage of the word.

I think it would be fair to describe this as a modern and quite reasonable
alternative to the venerable (see what I did there?) ZeroClipboard.

------
aykutcan
Browsers support clipboard events for a long time. Except safari. Because
Safari, we have to use that "flash & bloated frameworks".

Because "the people using safari" is still a thing (i dont know why)

~~~
ryanwaggoner
I use Safari because Firefox and Chrome are both bloated pieces of crap. I can
open 30 tabs simultaneously in Safari with minimal impact on my CPU, while
Chrome locks up for close to a minute as it tries to cope. Much better smooth
scrolling performance, integration with Safari on iOS, etc.

The only thing I wish Safari had that Chrome does is profiles.

~~~
jgalt212
I find Chrome to be a CPU hog. This may have to do with each tab running in
its own process. Can this be disabled, or can processes be suspended if they
are not the top tab?

I don't open a lot of tabs on Chrome because of this.

~~~
liveoneggs
[https://groups.google.com/a/chromium.org/forum/#!msg/chromiu...](https://groups.google.com/a/chromium.org/forum/#!msg/chromium-
dev/EUqoIz2iFU4/kPZ5ZK0K3gEJ)

