-
Hi, I've been writing a little application using Leptos and right now I need to create a button that copies a variable to the clipboard. Reading the book I believe I would have to use
I guess I'm trying to execute something like |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
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.
So, all in all, something like if let Some(clipboard) = window().navigator().clipboard() {
clipboard.write_text("foo bar baz");
} else {
// handle the lack of clipboard!
} making sure that you've enabled the |
Beta Was this translation helpful? Give feedback.
-
As of web-sys |
Beta Was this translation helpful? Give feedback.
Let me walk you through how I would figure this out, personally.
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.
web-sys
docs on docs.rsnavigator
: there's aNavigator
struct, and anavigator
method onWindow
, so we know thatwindow().navigator()
will return us the same thing as JSwindow.navigator
, which is also available asnavigator
in JSclipboard
: there's aClipboard
struct and aNavigator::clipboard
method, so I know thatwindow().navigator().clipboard()
will return us (clicks on link) anOpt…