9 ms·
Clipboard.js: Modern Copy to Clipboard
- kzhahou 11y agoSo 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 11y agoWell, 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.
- Osmose 11y agoWell, in this case it's being used with derision; it's deriding clipboard libraries that rely on hidden Flash players to get access to the clipboard.
- hayksaakian 11y agoI 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.
- yAnonymous 11y agoI mostly ignore Safari by now. I work around its worst limitations so the sites are usable, but that's it. Safari is the new Internet Explorer.
- babuskov 11y agoLet's see... Comes preinstalled with OS, has small memory footprint, very fast loading, low CPU usage and shitty support for newer web tech. Yup, all checks out.
- progx 11y agoSeems we have a new IE 6
- michaelwww 11y agoI came across an article yesterday that said this too. I don't know, I am not a Safari user, but I doubt Apple will take years to upgrade like IE6. http://nolanlawson.com/2015/06/30/safari-is-the-new-ie/ http://nolanlawson.com/2015/06/30/safari-is-the-new-ie/
- jacobolus 11y agoFunny. 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.
- rockdoe 11y agoIs it possible you're having this experience because Safari just is ignoring a whole bunch of stuff (that makes the web-pages slow and cumbersome) because it's too outdated to understand? Battery life it does have an advantage on, AFAIK this is widely understood and both Google and Mozilla are trying to address it (if they can, Apple does have nonpublic/undocumented APIs...). I'm surprised you find it outperforming Firefox wrt memory usage, though.
- huskyr 11y ago> (...) while Apple is taking a more measured approach with a focus > on performance and reliability. Good luck then trying to do anything complex with video and audio on iOS Safari. I've seen many weird quirks and bugs, strange limitations (videos always playing fullscreen on iPhone) and even browser crashes. And considering reliability: wouldn't you agree that we would be better of using a native solution for clipboard access than the buggy and insecure Flash fallback that's needed for Safari?
- awjr 11y ago
- lexicalscope 11y agoI actually was thinking that the graceful degrade was how it was implemented initially and was about to write it off until I got to that part. Interesting. At this point I still don't buy that Apple is doing this to hold things back. Do you have other examples of when they've been behind on features with no clear explanation of why? It's okay if not - you said you were only casually following - but curious. They wouldn't have very much to gain in my mind - none of their core business relies on locking in/out web development. They have an app market, and I guess you could argue they're trying to drive that, but they have implemented a lot of other features, and early extensions in many cases, that doesn't really align with them trying to hold web back.
- circlingthesun 11y agoWell, for one, local storage in private mode has been completely borked for at least for a couple of years now.
- moretti 11y agoSo Safari is holding back webdev because it doesn't support an experimental technology? Fun thing: the author of the Selection API draft works for Apple :-) http://www.w3.org/TR/selection-api http://www.w3.org/TR/selection-api
- davidcollantes 11y agoIt is working on Safari for me.
- realityking 11y agoThe Selection API works in Safari, what doesn't work is the clipboard API.
- atirip 11y agoWhy isn't this more common?!? Are you trolling? Every script copying random stuff (read marketing messages) into my clipboard, well sign me up, thats what i have sooo wanted for sooo many years. Luckily Safari is my browser of choice.
- deleted 11y ago[deleted]
- joshstrange 11y agoIIRC the clipboard copy only happens if you first click so it must be user-initiated. Now I'm sure using flash there are other sneaky ways to do it. For example some sights when you select text and copy it will attach the URL of the page your are on at the end of the text which drives me crazy. If I want the URL I'll copy it, until then stay out of my way.
- code_sterling 11y agoHardly. Different priorities. Safari on Mac is miles ahead on battery life and footprint. When I'm on a laptop, that matters way way more than any experimental feature. It's literally hours better. I have to ask though, what mission critical ratified features do you need that Safari lacks?
- pdkl95 11y agoMore common? It shouldn't exist at all. The potential use cases for manipulating the selection are at best a minor feature and sometimes a serious usability bug. Stop trying to give webpages control - any control at all - over the browser UI. The page gets to control just that (the page) and the framework around that page (the browser). Any violation of this a potential security problem. Any time the demarcation between "remote page" and "browser UI" is blurred, problems such as "phishing" attacks become easier. If you want fancier UI than is possible from a web page, write a native app.
- eponeponepon 11y agoAny time the demarcation between "remote page" and "browser UI" is blurred, problems such as "phishing" attacks become easier. Hugely important; largely ignored. Unfortunately, people whose training and experience exists only inside a browser either don't or can't see beyond those confines and the result is reimplementing perfectly adequate external functionality.
- henvic 11y agoThis is indeed a nice argument. Sometimes I am doing something on the CLI and go back to the terminal and paste a text I copied from somewhere. If the text is multiline my terminal will consume the lines without requiring an extra 'enter / return' key press. Another possibility is copying something to web mail client without noticing there's something suspicious about it (JS isn't the concern here anymore nowadays, but loading stuff like images is a privacy concern). However, this issue MUST be fixed at browser level. And when used without destroying user expectations / UX, this plugin is useful. Malicious attacks are going to happen anyways if the browser permit such action to happen, so don't blame the plugin or the plugin writer. The browsers are broken. Ask the major browser developers to either never allow it to happen (like Safari does) or ask them to ask for permission (like for webcams) or add a confirmation modal.
- pdkl95 11y agore: browser support (which is where this problem should be fixed) A trivial compromise that would be even easier to use than the current javascript/selection stuff would be a "copy to clipboard" variant of the <button> tag. Something like this should satisfy the use-cases where this clipboard nonsense is occasionally useful: <form> <input name="copy_souce" type="text" value="xyzzy" /> <button type="clipboard" value="copy_source" name="Copy To Clipboard" /> </form> This wouldn't require any Javascript, and leaves the clipboard entirely under the control of the user where it belongs. This could even be extended to allow copying of the various types of input tags, and if you wanted to get fancy, the button could reference an #id and copy that element's textContent (or innerHTML).
- cpeterso 11y agoZeroClipboard is adding support for the HTML5 clipboard API , while retaining Flash fallback for older browsers: https://github.com/zeroclipboard/zeroclipboard/issues/171 https://github.com/zeroclipboard/zeroclipboard/issues/171
- fokinsean 11y agoYup, Safari's lack of getUserMedia() is the sole reason we have to continue using flash at my job.
- eponeponepon 11y agoWhat 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 11y agoIt 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.
- Rifu 11y agoAnd for the truly adventurous, there's the html5 clipboard api.
- masklinn 11y agoIsn'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 11y agoThis is very true, though I was mostly commenting on the "Modern copy to clipboard" description.
- cpeterso 11y agoClipboard.js uses the HTML5 clipboard API.
- marwann 11y agoI'd love to see the ability to paste without using the keyboard too. Is that something possible/on the roadmap?
- ludwik 11y agoI don't think so. Ability to access information in user's system clipboard seems like a huge security and privacy issue.
- adzicg 11y agoexecCommand paste is limited by browsers, so synthetic events don't have the content (see section 8 of http://www.w3.org/TR/clipboard-apis/ http://www.w3.org/TR/clipboard-apis/). although that would increase the capabilities of web apps so people could nicely integrate custom copy/paste, it seems to be a security risk (eg you can grab the clipboard contents and paste to a hidden input field, then post to server without the user knowing). you can plug into the paste pipeline and replace the data pasted when a user causes paste, either by clipboard or clicking on the browser menu/context menu though, just using the html5 events. You don't need a separate library for that.
- KaiserPro 11y agoIn linux middle button pastes any previously highlighted text. its awesome.
- aykutcan 11y agoBrowsers 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 11y agoI 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 11y agoI 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 11y agohttps://groups.google.com/a/chromium.org/forum/#!msg/chromium-dev/EUqoIz2iFU4/kPZ5ZK0K3gEJ https://groups.google.com/a/chromium.org/forum/#!msg/chromiu...
- deleted 11y ago[deleted]
- zserge 11y agoGlad 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!
- welder 11y agoJust 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 11y agoThe 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 11y agoIt'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 11y ago> 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 11y agoWe 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.
- raverbashing 11y agoAnother trick using clipboards (in Mac OS X): use pbcopy/pbpaste to copy and paste to clipboard
- david-given 11y agoText 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.
- dijit 11y agoThere are legitimate cases to use something like this; for example, our organisation has a 'secret server', a centrally audited webserver which stores passwords and controls who can access which passwords. Personally I think the implementation is shitty.. but without displaying the password in cleartext, copying directly to the clipboard is a preferred solution. (even if you can potentially mis-paste.)
- 11y ago
- deejbee 11y agoDoes 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...
- lkjasdoiuqwe 11y agoThe 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...
- Killswitch 11y agoMicrosoft themselves aren't going to be supporting IE8 anymore after January. Let it go.
- nevi-me 11y agoIE8 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 11y agoI 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.
- Mahn 11y agoAccording to statcounter (which I'm not claiming is accurate, just the only up-to-date source I could find) as of August 2015 IE8 had a market share of 2.32%. You have to be really unlucky with your audience/service if you really need to support IE8.
- elwell 11y agoStarted project 13 days ago and has 4k+ GitHub Stars "This might come in handy; better star it."
- outsidetheparty 11y agoThe 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 11y agoI 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.
- mavster 11y agoOkay, who pressed the star button? https://github.com/zenorocha/clipboard.js/issues/56 https://github.com/zenorocha/clipboard.js/issues/56