How do I copy content thats present in a div tag and paste it to applications like Paint, Powerpoint etc.
            Asked
            
        
        
            Active
            
        
            Viewed 2.7k times
        
    5
            
            
         
    
    
        Gert Grenander
        
- 16,866
- 6
- 40
- 43
 
    
    
        rahul
        
- 77
- 1
- 1
- 3
- 
                    You should clarify your question. Do you want to CTRL+C CTRL+V something or what? – Mauro Aug 13 '10 at 08:55
- 
                    1possible duplicate of [Jquery - Copy div contents to clipboard](http://stackoverflow.com/questions/3308115/jquery-copy-div-contents-to-clipboard) – Gert Grenander Aug 13 '10 at 09:06
- 
                    possible duplicate of [Copy text to the client's clipboard using jQuery](http://stackoverflow.com/questions/1539641/copy-text-to-the-clients-clipboard-using-jquery) – kapa Apr 15 '11 at 06:24
- 
                    Take a look at this question: http://stackoverflow.com/questions/1539641/copy-text-to-the-clients-clipboard-using-jquery – jorgebg Aug 13 '10 at 08:55
- 
                    It seems from your later comments you want to copy as an image, this should have been made clearer in the question. – Luke H Dec 01 '12 at 09:57
- 
                    This seems to be what you're looking for http://stackoverflow.com/questions/5336102/how-to-save-specific-part-of-page-as-image-using-javascipt – Luke H Dec 01 '12 at 09:58
2 Answers
3
            
            
        It is not easy but possible:
function copyToClipboard(meintext) {  
if (window.clipboardData)   
     window.clipboardData.setData("Text", meintext);  
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 false;  
     var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);  
     if (!trans)  
          return false;  
     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);  
     str.data=meintext;  
     trans.setTransferData("text/unicode",str,meintext.length*2);  
     var clipid=Components.interfaces.nsIClipboard;  
     if (!clipid)  
          return false;  
     clip.setData(trans,null,clipid.kGlobalClipboard);  
}  
     return false;  
}
Please note. The first two lines are for IE.
All the following for Firefox. And for Firefox the clipboard has to be enabled:
Open about:config
set signed.applets.codebase_principal_support to true.
Or just use some Flash-stuff :)
 
    
    
        kapa
        
- 77,694
- 21
- 158
- 175
 
    
    
        Sebastian J.
        
- 762
- 9
- 29
