views:

434

answers:

3

How do I copy content thats present in a div tag and paste it to applications like Paint, Powerpoint etc.

+2  A: 

you can use jquery clipboard, check the homepage here

Nealv
+1  A: 

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 :)

zeeman
thanks but i need the content to be copied as a image not as a text.
rahul