Copy Text to Clipboard

I would like to copy text to the clipboard to help users transfer contact information from my website(s). Especially on phones, the select and copy operation can be cumbersome. Ideally I would create a button to copy text to the clipboard that I’ve preconfigured as a convenience similar to how “Open Mail” or “Go to External Link” operate where there is a single input defined by the developer and all the user has to do is click. So I created a button and of course among the list of convenient “On Click” features I didn’t find “Copy to Clipboard” in the list.

So I looked into embedding some code only to find that without a Button.On Click execute feature there was no way to link my Sparkle button click action to anything embedded and I’d have to code such a button from scratch. hmmm - I’d prefer to just stay in the visual development realm as much as possible to keep the management of my UI consistent and efficient.

In the end function outweighs form so I am hoping someone might have a clever workaround or a code snippet that actually works? The objective is simple - copy my predefined text to the clipboard. I would be satisfied if every time the page opened it just did that [copied my defined text to the clipboard] and I could use a Sparkle button for cosmetic theatre [on click=“Do Nothing”. User punches the button to copy Contact details when in reality the data was already there to begin with.

Quick and dirty way is to add this to an external link action:

javascript:navigator.clipboard.writeText('text here');

However the javascript clipboard feature is not supported by older browsers.

1 Like

I’ve tried various techniques with mixed results - overall disappointing… Even @Duncan javascript doesn’t work consistently or across devices that all use Safari. Rather surprising how challenging simply copying some Plain TEXT to the system clipboard can be. I can understand the security ramifications but…

I’ve decided to resort to a vCard download solution instead.

The difficulty of supporting the variety of browsers and platforms is not at all surprising to me. Sorry the straightforward solution didn’t work for you.