I am using the Accusoft document viewer. I have a requirement for a button that when clicked will copy to the clipboard the current URL plus a page number querystring parameter. I am using clipboard.js. I know exactly how to get the current URL and how to add a page number parameter to the URL. What I don't know how to do is make clipboard.js copy a variable (such as the generated URL with page number parameter) to the clipboard. Any help on this?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
By placing you variable's content into a div and then use it as a target for clipboard.js....
I have to admit I didn't tryed it, but it should should work.
Your button (the example of the clipboard.js site) :
Place your variable's content into the target div:
It is now ready to be copied.
-----
EDIT
Ok, after the discussion below, I really tried my solution by downloading
Clipboard.js
and tested it.(Someday I will learn to test my solutions before posting!)
Turns out that it works on a
div
only if visible.Sadly.
So my solution is wrong.
I leave it here anyway... As a "don't do it, it's a false-good idea".
Thanks to Michael Mahony for his feedback.
;)
Clipboard.js creator here ;)
You can use the imperative API to achieve that: