Placing text on Clipboard

20 views
Skip to first unread message

query

unread,
Jan 14, 2008, 3:19:51 PM1/14/08
to TiddlyWiki
I'd like to place text on a clipboard using Java and Firefox. In
searching for "Clipboard" in this forum I found some references saying
it couldn't be done, but then Jeremy Ruston said it could be done and
pointed to -

http://xulplanet.com/tutorials/xultu/clipboard.html

I've tried the code there and nothing happens and I'm wondering if
anyone knows how to do this.

Thanks

Eric Shulman

unread,
Jan 14, 2008, 3:34:47 PM1/14/08
to TiddlyWiki
> I'd like to place text on a clipboard using Java and Firefox. In

That's javaSCRIPT... "Java" is a different language entirely.

> http://xulplanet.com/tutorials/xultu/clipboard.html
> I've tried the code there and nothing happens and I'm wondering if
> anyone knows how to do this.

How did you try the code? Where did you put it and how did you
trigger it? What were the steps you used to test, and how do you know
that "nothing" happened? Can you post an example of your code (or
better yet, a URL to the actual TW document, hosted online
somewhere... like TiddlySpot)

-e
Eric Shulman
TiddlyTools / ELS Design Studios

query

unread,
Jan 14, 2008, 3:44:14 PM1/14/08
to TiddlyWiki
Sorry, my head is faster than my fingers sometimes - javaSCRIPT it is.
The code is -

const gClipboardHelper = Components.classes["@mozilla.org/widget/
clipboardhelper;
1"] .getService(Components.interfaces.nsIClipboardHelper);
gClipboardHelper.copyString("Put me on the clipboard, please.");

Placed between script tags on a single HTML file.

"Put me on the clipboard.." isn't there.

Thanks.

Eric Shulman

unread,
Jan 14, 2008, 3:49:50 PM1/14/08
to TiddlyWiki
> http://xulplanet.com/tutorials/xultu/clipboard.html
> I've tried the code there and nothing happens and I'm wondering if
> anyone knows how to do this.

The code suggested on XULPlanet was producing a "permission denied"
error. This is because it first needs to be granted security
permissions in order to successfully access the clipboard...

The following code works in TW (using InlineJavascriptPlugin under
FireFox):
---------------
<script label="click to enter text">
if(!window.Components) return;
try
{ netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); }
catch(e) { alert(e.description?e.description:e.toString()); return; }
const clip=Components.classes["@mozilla.org/widget/clipboardhelper;
1"].getService(Components.interfaces.nsIClipboardHelper);
clip.copyString(prompt("please enter text to put on clipboard"));
</script>
Paste text here to confirm clipboard contents:
<html><textarea rows=5 cols=50></textarea></html>
---------------


enjoy,

query

unread,
Jan 14, 2008, 4:03:53 PM1/14/08
to TiddlyWiki
Eric,

Thanks, works perfectly.

You are frighteningly good at this..........
Reply all
Reply to author
Forward
0 new messages