Amphtml: Support for copying to clipboard

Created on 8 Sep 2016  ยท  24Comments  ยท  Source: ampproject/amphtml

Description

Our pages allow users to copy the share URL, (in addition to basic social sharing). To allow our pages to support AMP, we need to be able to copy content to clipboard without JS.

Current feature is provided by a 3rd party tool clipboardjs. We cannot find equivalent functionality.

Example

https://gfycat.com/BareSecondaryFlamingo
Click on the embed button below the video
Click on the copy to clipboard icon

All New Feature Developer Soon DevX Feature Request components

Most helpful comment

cc @nainar - can you investigate prioritization?

All 24 comments

This would be great, as long as we don't do the spammy text-selection hijacking.

Would be a neat addition to amp-social-share.

@koshka Would you be interested in implementing this and contributing it to the project?

Hello! As per the Contributing Guidelines I'd like to show an "intent to implement", a Pull request for this issue.

I plan on using something like: https://www.sitepoint.com/javascript-copy-to-clipboard/ , and clipboard.js for any other reference :smile:

I agree with @jridgewell, and try to make the component specifically display the text that will be copied.

@torch2424: That'd be lovely.

I wonder if requiring the show the URL is a little too opinionated. Awesome you are working on this @torch2424!!

Just Finished this. Probably have a PR opened in today, or within the next week. Currently wrapping up the validator, and some Docs

It was concluded that due to lack of cross browser support, this is infeasible. Should not be a GFI candidate anymroe.

<amp-story> supports this. Given that, is there any reason <amp-social-share> can't?

We should definitely support copy to clipboard.

On Thu, Mar 29, 2018 at 10:01 AM, Taymon A. Beal notifications@github.com
wrote:

supports this. Given that, is there any reason
can't?

โ€”
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/ampproject/amphtml/issues/4853#issuecomment-377302861,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAFeTz-gjsvL4eH1__wmbfjwNR20IoS4ks5tjRNigaJpZM4J3dmW
.

As a drive-by comment: we implement this with an amp-iframe that just loads a tiny page containing a copy button with regular JS. We have a placeholder button in the top-level page, which is almost immediately replaced with the iframe.

Just wanted to bump this a little bit, totally forgot, but @sebastianbenz and I discussed how this would be really helpful for AMP By Example, and the upcoming amp.dev at the contributor summit. Would be cool if we could get something going on this, especially since a lot of issues I had with my original PR, are now fixed in later versions of mobile safari (i think) ๐Ÿ˜„

@samthor Thank you for this! Great that we have a link in the issue in case someone else comes across this ๐Ÿ‘

For amp.dev it'd be great to have the ability to copy code snippets from the documentation samples. For this case It'd be great to have a simple copy action which specifies a node and recursively concatenates all child text nodes to a single string which is then added to the clipboard:

<button on="tap:mySnippet.copyToClipboard">
<pre id="mySnippet">
Code ...
</pre>

Hey @torch2424 are there any updates on this? It'd be really fantastic to have this available for amp.dev.

@sebastianbenz My apologies! Wasn't sure if the iframe solution would suffice or not. I will pass this around the team in mountain view, and see if we can get some traction on this ๐Ÿ‘

cc @nainar - can you investigate prioritization?

I'll let @nainar investigate/prioritize this. Feel free to reach out to me on this topic, I actually made an extension for this about a year and a half ago, so before we start implementation perhaps we can possibly re-use some of that code (probably not though).

Thanks for catching this @rudygalfi ! ๐Ÿ˜„

@aghassemi You marked this "soon" about 6 months ago. Is there any plans to work on it ? Thank you !

Hi @catherinehoule, would the solution outlined on https://ampbyexample.com/advanced/copy_button/preview/ work for you and unblock you?

@aghassemi That works but feels a bit hacky... I was wondering if there was plans to make this issue happening since it's been sitting in soon state for a while. Thanks for the quick answer !

@aghassemi Would you happen to have a solution that works with a screen reader using the arrows.
On mac, it works using the tab to navigate thru button in the example then click but still screen readers users uses arrow to read documents. And on PC I've been told that it doesn't work at all.
(I tried adding keypressed to the onclick)

Using Iframe for copy seems to be a overkill.
For me I just needed a button to allow users to copy Email ID,
Just to make it easier. But including Iframe Javascript will make the page heavier.

What is the best solution?

Just came across this. I have a WordPress plugin for adding syntax highlighting to code blocks (which is used on blog.amp.dev). Various users have asked for a Copy to Clipboard button to go next to the code block: https://github.com/westonruter/syntax-highlighting-code-block/issues/192

But this is blocked by not having the capability in AMP.

Was this page helpful?
0 / 5 - 0 ratings