Skip to content

How to create a Copy to Clipboard Button #2399

Answered by gbj
mariinkys asked this question in Q&A
Discussion options

You must be logged in to vote

Let me walk you through how I would figure this out, personally.

navigator.clipboard.writeText(copyText);

Whenever I am trying to use a JS interface from Rust, I start with the fact that every browser API/item is available -- usually, globals or getters are available as function calls.

  1. Open web-sys docs on docs.rs
  2. Search navigator: there's a Navigator struct, and a navigator method on Window, so we know that window().navigator() will return us the same thing as JS window.navigator, which is also available as navigator in JS
  3. Search clipboard: there's a Clipboard struct and a Navigator::clipboard method, so I know that window().navigator().clipboard() will return us (clicks on link) an Opt…

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
6 replies
@mariinkys
Comment options

@mariinkys
Comment options

@gbj
Comment options

gbj Mar 6, 2024
Maintainer

@mariinkys
Comment options

@pheki
Comment options

Answer selected by mariinkys
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants