4 ms·
Programmatic cut and copy to the clipboard It’s now possible to programmatically copy and cut text in response to a user gesture with document.execCommand('copy
by sergiotapia 11y ago
Programmatic cut and copy to the clipboard
It’s now possible to programmatically copy and cut text in response to a user gesture with document.execCommand('copy') and document.execCommand('cut'). Having this ability may eliminate some websites’ last need for the Flash plug-in.
---
:'( - So much pain erased in a single stroke!
- Alex3917 11y agoUnfortunately as far as I know the text selection API is still broken on mobile Safari. At least as of a few weeks ago the JS events associated with force touch seem to randomly wipe out the text selection, so even if you can now theoretically copy stuff to the clipboard it's largely irrelevant if users can't actually select text in the first place.
- om2 11y agoCan you file a bug with a specific example or two? http://bugs.webkit.org/ http://bugs.webkit.org/
- Alex3917 11y agoI think my cofounder already did, I'll check. The basic issue we were encountering is that when selecting text via force touching and then dragging the selection, the text selection object was empty. (Though you can still hit Copy in the Safari UI.) There wasn't any issue when selecting text via regular press or long press.
- agopaul 11y agoThat sucks. But (Desktop) Chrome/webkit selection has been partly broken too for a few years now. https://bugs.webkit.org/show_bug.cgi?id=66630 https://bugs.webkit.org/show_bug.cgi?id=66630 https://bugs.chromium.org/p/chromium/issues/detail?id=346613 https://bugs.chromium.org/p/chromium/issues/detail?id=346613 I've been dealing with this stuff for the last week. Edit: added webkit reference
- chiph 11y agoI wouldn't ever enable clipboard integration -- a malicious site could use it to collect data by using the paste command with execCommand -- they'd grab whatever was on my clipboard, which could include my banking password from my password manager app that I was just getting ready to use.
- om2 11y agoThat's why they only get the ability to programmatically trigger cut and copy, not paste.
- frou_dh 11y agoI guess there's room for an attack of irritation where a user with something meaningful on their clipboard unwittingly triggers having it overwritten by some nonsense. (Most clipboards effectively being a single mutable item without history or stack/queue behaviour).
- scrollaway 11y agoThere's easier ways to irritate your users. Most websites irritate their users, actually.
- frou_dh 11y agoSpeaking of clipboard shenanigans. Could be imagining it, but I seem to remember a while ago there being something certain websites were doing where if you selected and copied text from them, the text that ended up on your clipboard would have a synthesized paragraph about copyright/attribution appended to it.
- scrollaway 11y agoYeah, occured to me reading that comment. Lyrics websites used to do it a lot (probably still do). I believe they use invisible text.
- ryan_lane 11y agoI do wonder why they didn't go with an API that other browsers are already supporting, though: https://developer.mozilla.org/en-US/docs/Web/API/ClipboardEvent https://developer.mozilla.org/en-US/docs/Web/API/ClipboardEv...
- om2 11y agoOther browsers support the execCommand API as well. Adding a new, arguably cleaner API is a separate undertaking from removing the unnecessary limitation on the older API.
- masklinn 11y agoDid you consider reading the page you linked to? Clipboard events are already supported by safari (which the page you've linked to notes) and they've got nothing to do with execCommand, they are about hooking and reacting to user-triggered clipboard operations e.g. the user pastes (via contextual menu or shortcut), the software can know about it and alter the content before it's pasted. execCommand is about programmatically triggering clipboard events e.g. the user clicks a button in the page and the application translates that to a copy or paste event.
- DigitalJack 11y agoDid you consider removing the first sentence of your post and it would have been less smug and taunting, leaving behind something that lifts up the conversation?
- masklinn 11y ago> Did you consider removing the first sentence of your post and it would have been less smug and taunting Did you consider taking your own advice? > leaving behind something that lifts up the conversation? What are you talking about? There is no conversation, and what this subthread needs is not uplifting is euthanising.
- Matt3o12_ 11y agoIt's probably only a matter of time but I worry that some advertisers copy ad links to my clipboard. With flash, I had to allow it at least...