Copy & Paste JavaScript Codes for popular browse like IE,Firefox and opera etc

Applications-Folder-48x48 Copy & Paste JavaScript Codes for pop browse like IE,Firefox and opera etcThe function belows that can copy & paste text contents for pop browselike IE,Firefox and opera etc.You can download the source from here >>>copyToClipboard.js

copyToClipboard = function(txt) {
if(window.clipboardData) {
  window.clipboardData.clearData();
  window.clipboardData.setData("Text", txt);
} else if(navigator.userAgent.indexOf("Opera") != -1) {
window.location = txt;
} else if (window.netscape) {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
} catch (e) {
alert("You need set 'signed.applets.codebase_principal_support=true'
at about:config'");
return false;
}
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 = txt;
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);
}
}
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • Reddit
  • Technorati
  • StumbleUpon
  • Twitter
RSS Enjoy this Post? Subscribe to Ntt.cc

RSS Feed   RSS Feed     Email Feed  Email Feed Follow us Follow us
You can leave a response, or trackback from your own site.

3 Responses to “Copy & Paste JavaScript Codes for popular browse like IE,Firefox and opera etc”

  1. Yuri Cardenas says:

    It would be a good idea if you also post a link where people can find an explanation about the use of the components and classes you’ve got in your code.

    For example: https://developer.mozilla.org/en/Using_the_Clipboard

  2. Ntt.cc says:

    @Yuri Cardenas

    Thanks very much!! :)

  3. Cosimo says:

    I don’t understand the opera part (window.location = ‘…’).

    It doesn’t work for me, on Opera 9.6x.
    Is that correct?

Leave a Reply