What is the best way to copy text to the clipboard? (multi-browser)
I have tried:
function copyToClipboard(text)
{
if (window.clipboardData) // IE
{
window.clipboardData.setData("Text", text);
}
else
{
unsafeWindow.netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
const clipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper);
clipboardHelper.copyString(text);
}
}
but in Internet Explorer gives a syntax error. In Firefox it says "unsafeWindow is not defined".