Page 1 of 1
copy to clipboard in firefox
Posted: Sat Aug 05, 2006 12:49 pm
by Burrito
is it possible to copy a string to the clipboard using firefox like it is with IE?
I think I read somewhere that it is, but you don't use the same object.
any ideas?
Posted: Sat Aug 05, 2006 1:13 pm
by thiscatis
I know it can't be done with advanced WYSIWYG editors like tiny_mce and fck_editor so I don't think so..
ctrl-c ctrl-v only...
But if anyone knows something about this issue, i'm looking forward to your reply

Posted: Sat Aug 05, 2006 1:56 pm
by Buddha443556
There's an xulplanet.com's tutorial for
Using the Clipboard. However, you'll get a
'Permission denied to get property UnnamedClass.classes' error. You'll have to use signed code or install some chrome. Might want to look into netscape.security.PrivilegeManager.enablePrivilege() and file://.
Here's something on
Signed Scripts in Mozilla.
Posted: Sat Aug 05, 2006 4:59 pm
by Burrito
this is what I came up with after doing a little more research.
Code: Select all
<script language="javascript" type="text/javascript">
<!--
function copy_clip(thetext)
{
if (window.clipboardData)
{
window.clipboardData.setData("Text", thetext);
}
else if (window.netscape)
{
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var clip = Components.classes['@mozilla.org/widget/clipboard;1']
.createInstance(Components.interfaces.nsIClipboard);
if (!clip) return;
var trans = Components.classes['@mozilla.org/widget/transferable;1']
.createInstance(Components.interfaces.nsITransferable);
if (!trans) return;
trans.addDataFlavor('text/unicode');
var str = new Object();
var len = new Object();
var str = Components.classes["@mozilla.org/supports-string;1"]
.createInstance(Components.interfaces.nsISupportsString);
var copytext=thetext;
str.data=copytext;
trans.setTransferData("text/unicode",str,copytext.length*2);
var clipid=Components.interfaces.nsIClipboard;
if (!clip) return false;
clip.setData(trans,null,clipid.kGlobalClipboard);
}
return false;
}
//-->
</script>
to make this work, I had to change a security setting in FF on about:config
I had to change (signed.applets.codebase_principal_support) to true. Now it prompts me and asks if I want to allow it...since all of these will be run on my own sites, I accepted and I'm now a happy man
