How do I copy content thats present in a div
tag and paste it to applications like Paint, Powerpoint etc.
views:
434answers:
3Take a look at this question: http://stackoverflow.com/questions/1539641/copy-text-to-the-clients-clipboard-using-jquery
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 :)