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

  1. copyToClipboard = function(txt) {
  2. if(window.clipboardData) {
  3.   window.clipboardData.clearData();
  4.   window.clipboardData.setData("Text", txt);
  5. } else if(navigator.userAgent.indexOf("Opera") != -1) {
  6. window.location = txt;
  7. } else if (window.netscape) {
  8. try {
  9. netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  10. } catch (e) {
  11. alert("You need set 'signed.applets.codebase_principal_support=true'
  12. at about:config'");
  13. return false;
  14. }
  15. var clip =
  16.  Components.classes['@mozilla.org/widget/clipboard;1′].createInstance
  17. (Components.interfaces.nsIClipboard);
  18. if (!clip)
  19. return;
  20. var trans =
  21. Components.classes['@mozilla.org/widget/transferable;1].createInstance
  22. (Components.interfaces.nsITransferable);
  23. if (!trans)
  24. return;
  25. trans.addDataFlavor('text/unicode');
  26. var str = new Object();
  27. var len = new Object();
  28. var str =
  29. Components.classes["@mozilla.org/supports-string;1″].createInstance
  30. (Components.interfaces.nsISupportsString);
  31. var copytext = txt;
  32. str.data = copytext;
  33. trans.setTransferData("text/unicode",str,copytext.length*2);
  34. var clipid = Components.interfaces.nsIClipboard;
  35. if (!clip)
  36. return false;
  37. clip.setData(trans,null,clipid.kGlobalClipboard);
  38. }
  39. }
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
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