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.