Discuss Scratch

1132262
Scratcher
1000+ posts

JS Bookmarklet to Copy a Unicode character to clipboard

I'm wondering how I could make a bookmarklet that, when clicked, copies the U202A character to my clipboard (No, not for collaborative text-editing rap battles. I promise.)
I've looked, and there doesn't seem to be an intuitive way to do this. All the APIs I've seen use HTML elements as input.
Any suggestions?

Mod: (Removed a link - I love xkcd but we do need to keep language all-ages, sorry. :( )

Last edited by Harakou (May 10, 2020 18:25:03)


!!
Sheep_maker
Scratcher
1000+ posts

JS Bookmarklet to Copy a Unicode character to clipboard

You could try navigator.clipboard.writeText:
navigator.clipboard.writeText('\u202a')
It's possible that it can only be run in certain event handlers like in a click event listener, but this depends on the browser

- Sheep_maker This is a kumquat-free signature. :P
This is my signature. It appears below all my posts. Discuss it on my profile, not the forums. Here's how to make your own.
.postsignature { overflow: auto; } .scratchblocks { overflow-x: auto; overflow-y: hidden; }
1132262
Scratcher
1000+ posts

JS Bookmarklet to Copy a Unicode character to clipboard

Sheep_maker wrote:

You could try navigator.clipboard.writeText:
navigator.clipboard.writeText('\u202a')
It's possible that it can only be run in certain event handlers like in a click event listener, but this depends on the browser
Thanks!
:‪)

Last edited by 1132262 (May 10, 2020 18:50:03)


!!

Powered by DjangoBB