Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack (4) Thread Tools Display Modes
Old 06-01-2008, 05:32 PM   4 links from elsewhere to this Post. Click to view. #1 (permalink)
Web Junky 2.0
 
debiprasad_sahoo's Avatar
 
Join Date: Oct 2005
Location: Chennai, Cuttack
Posts: 121
Exclamation How to Copy to Clipboard in Firefox and other browsers other than IE?


Dear friends, I need to copy some contents to clipboard on the click event of a button. For IE the js code is as follow
Code:
window.clipboardData.setData('Text', 'the text you need to copy');
For firefox there is some complex code, which can copy to clipboard, but it is not working correctly. It shows this error
Quote:
uncaught exception: A script from "http://loveorkut.com/" was denied UniversalXPConnect Privilages.
The js code is as follow
Code:
        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 = "The Text you want to copy";
       
        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);
However this code works in local, it asks for a confirmation only to give access to the clipboard. I need this to be worked in Internet also. Any other good code will be better. Please help.

If you have any questions or ideas, then please discuss here.
__________________
More reason to love orkut
Get Scraps, Testimonials and many more...
http://loveorkut.com/
debiprasad_sahoo is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 07-01-2008, 08:19 AM   #2 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: How to Copy to Clipboard in Firefox and other browsers other than IE?

Mozilla doesn't allow copying to clipboard unless the script is signed (Digital signatures, from Verizon, etc.). And even if its signed it asks for user permission before allowing the script to do so.

But there is one hack, it uses a flash object to perform the same task and doesn't require permissions, etc. You may use it from here: http://www.jeffothy.com/weblog/clipboard-copy/

(P.s. There is a setting in About:Config which allows script to copy to clipboard, but it makes no sense asking a user to change all those defaults, etc.)

Or go the Mozilla's ugly and long way: http://developer.mozilla.org/en/docs..._the_Clipboard
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 07-01-2008, 08:48 AM   #3 (permalink)
Still Shining!
 
Lucky_star's Avatar
 
Join Date: Nov 2006
Location: Up 'n' above
Posts: 1,174
Default Re: How to Copy to Clipboard in Firefox and other browsers other than IE?

There is this flash component which allows copying to clipboard from any browsers. Its not designed by me. But I had used it once and its working in almost all browsers I have tested. I am not getting the exact source of this file. But its released under the GPL, so freely distributable.

Download this file: http://rapidshare.com/files/81866988...board.swf.html
Keep it in the same folder.

Here is the code:


Code:
<script type="text/javascript">
function copy(text2copy) {
  if (window.clipboardData) {
    window.clipboardData.setData("Text",text2copy);
  } else {
    var flashcopier = 'flashcopier';
    if(!document.getElementById(flashcopier)) {
      var divholder = document.createElement('div');
      divholder.id = flashcopier;
      document.body.appendChild(divholder);
    }
    document.getElementById(flashcopier).innerHTML = '';
    var divinfo = '<embed src="_clipboard.swf" FlashVars="clipboard='+escape(text2copy)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    document.getElementById(flashcopier).innerHTML = divinfo;
    }
}

</script>
Now pass any parameters to the function copy(parameters) and it will be copied to the clipboard instantly.

Like this:
Code:
<input type="button" onClick="copy('ThinkDigit Forum')">
This will copy Thinkdigit Forum to the Clipboard.
Tell me if you have any problems.
__________________
Simplicity is the ultimate Sophistication
HP dv6 6121tx: Core i7 2630 QM | 4GB | AMD 6770M 2GB GDDR5 | 640 GB
Nokia N86 8MP
Lucky_star is offline  
Old 07-01-2008, 09:53 AM   #4 (permalink)
Dreamweaver
 
Gigacore's Avatar
 
Join Date: Aug 2006
Location: Bangalore
Posts: 3,904
Default Re: How to Copy to Clipboard in Firefox and other browsers other than IE?

^ yup.. it must work !
__________________
Today's noobs are tomorrow's geeks. Don't make fun of them.. encourage them. - Gigacore

Follow me on twitter.com/gigacore
Gigacore is offline  
Old 26-01-2008, 01:32 PM   #5 (permalink)
Web Junky 2.0
 
debiprasad_sahoo's Avatar
 
Join Date: Oct 2005
Location: Chennai, Cuttack
Posts: 121
Default Re: How to Copy to Clipboard in Firefox and other browsers other than IE?

Quote:
Originally Posted by Lucky_star View Post
Tell me if you have any problems.
I was bit busy. That's is why I can not test it. Today I tested it. It works fine in IE, Firefox and Opera. Thank you.
__________________
More reason to love orkut
Get Scraps, Testimonials and many more...
http://loveorkut.com/
debiprasad_sahoo is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


LinkBacks (?)
LinkBack to this Thread: http://www.thinkdigit.com/forum/programming/77544-how-copy-clipboard-firefox-other-browsers-other-than-ie.html
Posted By For Type Date
??js??firefox?????? - Firefox ??? - ?? @ Mozest.com - Mozilla ?? This thread Refback 29-03-2012 12:18 PM
添加js代码firefox无法复制内容 - Firefox 桌面版 4.0.* - 广场 @ Mozest.com - Mozilla 中文支持社区与中文本地化网站 This thread Refback 09-04-2011 02:29 PM
添加js代码firefox无法复制内容 - Firefox 4.0.* - 广场 @ Mozest.com - Mozilla 中文支持社区与中文本地化网站 This thread Refback 30-03-2011 05:43 PM
添加js代码firefox无法复制内容 - Firefox 4 专区 - 广场 @ Mozest.com - Mozilla 中文支持社区与中文本地化网站 This thread Refback 30-03-2011 10:29 AM

Similar Threads
Thread Thread Starter Forum Replies Last Post
Now ... u can protect ur clipboard theft in IE7. anandk Tutorials 2 23-12-2006 05:58 PM
Windows Clipboard s18000rpm Software Q&A 4 28-08-2006 02:49 PM
Browsers, Firefox: Make firefox 10x faster, 100% working saipothuri Software Q&A 2 13-08-2006 11:33 AM
Clipboard Pragadheesh QnA (read only) 3 11-08-2006 08:46 PM

 
Latest Threads
- by Charan
- by Sarath
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 12:47 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2