I’m trying to write a little bookmarklet that can extract some text from the active page and load that into the clipboard.
The extraction is easy enough, but I’m really stuck doing the clipboard-copying part. Currently, I’m just alerting the text and hitting Ctrl+C to copy the text from the message-box, which isn’t ideal.
I’ve read How to Copy to Clipboard in JavaScript and other questions that suggest I use zeroclipboard, but I have no idea how one would make that work from a bookmarklet, considering I have to load external flash and javascript resources to be able to use the library.
I have no issues with messing up the page’s DOM to accomplish this or having to enable some permissions on my browser (Google Chrome), considering this is just a private bookmarklet.
Any pointers would be appreciated.
A couple disclaimers:
I made a bookmarklet generator a while back to make it easier for me to create bookmarklets.
It’s jQuery enabled, but that doesn’t mean you have to use jQuery.
You can check out the source to see how to import another script/library into a page via a bookmarklet.
In particular, the lines that import jQuery:
I hope that helps.