copy to clipboard in firefox

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

copy to clipboard in firefox

Post 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?
thiscatis
Forum Contributor
Posts: 434
Joined: Thu Jul 20, 2006 11:00 am

Post 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 ;)
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post 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.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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 Image
Post Reply