Copy to Clibboard button
Can I create a button to select the contents of a field and copy them to Clipboard? (In FM Pro that was v straightforward)
71 replies
-
I want to let you know that the solutions you have presented are exactly what I have been looking for for a long time. However, I have a small problem that I have not been able to solve: I cannot make the text preserve line breaks when copying it. Instead, it gets copied all together, and my desire is to copy it with the line break format. Is this possible?
-
I was very surprised when I first saw that this thread had a "pinned" and "accepted" answer. I haven't seen this anywhere else on the forum. It is more surprising given that execCommand() was deprecated at least 6 months before I posted the first version and that was nearly 3.5 years ago. I didn't discover that it was deprecated until yesterday.
posted a more modern version in this thread using the Clipboard API, but it is tied to the Ninext project which isn't required to use it. I mean no disrespect towards Jacques and I am still amazed by the discoveries and contributions he has made.
Even though execCommand() has been deprecated, it is still supported. Even though MDN states that Clipboard API has "Limited availability", it seems to be widely supported. I also figured out some of styling really isn't necessary in the version I posted. Anyway, here is a new version that will use the Clipboard API if it's available and use the execCommand() version if not.
html(" <button onclick='pasteToClipboard(""" + replace(text, " ", "\n") + """)'>Paste</button> <script> function pasteToClipboard(str) { if (navigator.clipboard) { navigator.clipboard.writeText(str) } else { let textArea = document.createElement('textarea'); textArea.value = str; document.body.appendChild(textArea); textArea.select(); document.execCommand('copy'); document.body.removeChild(textArea); } } </script> ")
-
where you can write html code? thank you silvia
Content aside
- Status Answered
-
1
Likes
- 8 mths agoLast active
- 71Replies
- 7570Views
-
10
Following