Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,184
    Thanks
    10
    Thanked 569 Times in 550 Posts

    Copy to Clipboard

    Here is a simple way to place small bits of text upon the user's clipboard.

    Normally restricted by browser security, the clipboard is freely open to flash.
    this function uses a simple flash app to dump to the clipboard.
    It avoids any kind of user warning or confirmation regarding the clipboard that characterize JavaScript-only solutions.


    Thus, it requires flash to be installed.

    Code:
    function copy(str) {
       var D=document;
        if(!copy.div) { copy.div = D.createElement('div'); D.body.appendChild(copy.div);  }
     
    flashVar = "Q1dTB3kAAAB4nKtgYI1nYOBfwMDAw8jgzPT//3975lAGBoYOdQYWhu\
    SczIKk/MSiFIac1Lz0kgyG4MriktRchuLUEme41DQmBg4GGRDJ6Cc0l4l  BAibCzsDO\
    CDSJgwksyRwkzuAA5AIAd7oY/w==";
     
    copy.div.innerHTML =  '<embed src="'+flashVar+'" FlashVars="clipboard='+encodeURIComponent(str) +
        '" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    }

    Example:
    Code:
      copy("Hello World!");
    -Run above then press <CRTL>+<V> in a text area.
    -It should say Hello World!

    It is limited in the amount of data it can copy, about 2-4kb.
    It also cannot read the clipboard at all, so don't bother to try.

    Despite it's shortcomings, i still find it very useful, and hope you might as well.



    Comments and questions welcome.
    Last edited by rnd me; 10-10-2008 at 04:41 PM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    With Flash 10, which was just released, Adobe straightened the security and among other things now requires user interaction to access local file system or clipboard.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,184
    Thanks
    10
    Thanked 569 Times in 550 Posts
    those bums!

    thanks for the heads up.

    are you saying the code will not work, or is it just an extra click now?
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • Users who have thanked liorean for this post:

    oesxyl (10-22-2008)

  • #5
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,184
    Thanks
    10
    Thanked 569 Times in 550 Posts
    DO NOT USE

    consider this script now dead.

    thank you adobe.

    if i can find access to copy of flash 10, i will rewrite it into a pop-up version that works.

    I will re-post here if that ever happens.
    Last edited by rnd me; 10-22-2008 at 06:16 PM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  • Users who have thanked rnd me for this post:

    oesxyl (10-22-2008)

  • #6
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Stupid Adobe!

    Pls update this code if you can and do let us know. Thanks thanks thanks!

  • #7
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,184
    Thanks
    10
    Thanked 569 Times in 550 Posts
    well, there are two main obsticles to me updating the code:
    1. I don't own or have access to flash 10.
    2. I don't program in flash.

    i found the auto-copy flash file online. i simply wrote the compact and effective wrapper function that uses the flash.

    since there seems to be some who are bummed about this script breaking, i offer some other, lesser, clipboard functions below.

    none of them are cross-browser like the flash, and imho, not as good.
    they are vendor specific, so third-party browsers are excluded.

    still, they might be better than nothing. They would be fine for building your own application to run on your browser, and perhaps your friend's browser as well, if you help them set it up.

    I would NOT use the below code on a site aimed at the general public.

    Code:
    //text version for IE5-8 and firefox 2-3:
    function CBtxt(f) {var bP = typeof f == "undefined";if (window.clipboardData) {if (!bP) {window.clipboardData.setData("Text", f);return;}return window.clipboardData.getData("Text");} else {FT = "text/unicode";CI = Components.interfaces;Cb = CI.nsIClipboard;C = Components;Cs = CI.nsISupportsString;Cm = "@mozilla.org";Cmw = Cm + "/widget/clipboard;1";try {netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");e = C.classes[Cmw].createInstance(Cb);var clip = C.classes[Cmw].getService(Cb);} catch (e2) {return;}try {b = C.classes[Cm + "/widget/transferable;1"].createInstance(CI.nsITransferable);} catch (e3) {return;}b.addDataFlavor(FT);if (typeof f == "undefined") {clip.getData(b, clip.kGlobalClipboard);var str = {};var strLength = {};b.getTransferData(FT, str, strLength);if (str) {str = str.value.QueryInterface(Cs);}if (str) {f = str.data.substring(0, strLength.value / 2);}return f;}o = C.classes[Cm + "/supports-string;1"].createInstance(Cs);o.data = f;b.setTransferData(FT, o, f.length * 2);try {t = CI.nsIClipboard;} catch (e4) {return;}e.setData(b, null, t.kGlobalClipboard);return;}return;}
    
    
    //IE only text version:
    function CB(){ //sets or read clipboard in IE accepts 1 arg to set, returns cb when empty
    if (arguments.length)     {window.clipboardData.setData('Text', arguments[0])}
    else 	{ return window.clipboardData.getData('Text')}
     }//end CB
    
    
    //version that supports HTML markup (DOM source) for firefox only:
    function CB(f) {if (!f) {f = undefined;}var bP = typeof f == "undefined"; var FT = "text/unicode";var CI = Components.interfaces;var Cb = CI.nsIClipboard;var C = Components;var Cs = CI.nsISupportsString;var Cm = "@mozilla.org";var Cmw = Cm + "/widget/clipboard;1";try {netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");var e = C.classes[Cmw].createInstance(Cb);var clip = C.classes[Cmw].getService(Cb);} catch (e2) {return;}try {var b = C.classes[Cm + "/widget/transferable;1"].createInstance(CI.nsITransferable);} catch (e3) {return;}b.addDataFlavor("text/html");b.addDataFlavor(FT);if (!f) {clip.getData(b, clip.kGlobalClipboard);var str = {};var bestFlavor = {};var strLength = {};b.getAnyTransferData(bestFlavor, str, strLength);if (bestFlavor.value == "text/html" || bestFlavor.value == "text/unicode") {if (str) {str = str.value.QueryInterface(Cs);}if (str) {f = str.data.substring(0, strLength.value / 2);}}return f;}var o = C.classes[Cm + "/supports-string;1"].createInstance(Cs);o.data = f;b.setTransferData(FT, o, f.length * 2);try {var t = CI.nsIClipboard;} catch (e4) {return;}e.setData(b, null, t.kGlobalClipboard);return;}
    like i said, don't use these on your blog and expect them to work.

    unlike the flash version, IE and firefox will ask for confirmation before allowing clipboard access.

    Firefox users:
    you must make a modification to about:config to get this code to work:
    change signed.applets.codebase_principal_support to true.

    note that this opens up firefox to enhanced capabilities like local file reading, clipboard access and cross-domain ajax. It will always first prompt the user to ask if these capabilities are trusted for the site. you should always click "deny" if you don't 100&#37; trust the webpage asking.

    if you don't modify about:config, the user will never be asked, and the script will silently die.

    While i dont use the code in web pages, i find the clipboard the fastest and simplest way to "talk" to exes and other applications, so i find it useful in my own work.

    hope someone else can use this code, and if i ever do update the flash version, i will be sure to post the results here.
    Last edited by rnd me; 10-22-2008 at 10:19 PM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  • #8
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Flash Player 10 Copy To Clipboard Library -- ZeroClipboard

    Hey guys,

    Here is a free, JavaScript / Flash library for offering copy-to-clipboard functionality in your web pages. It is fully compatible with Flash Player 10.

    http://code.google.com/p/zeroclipboard/

    Enjoy!

    - Joe

  • #9
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,184
    Thanks
    10
    Thanked 569 Times in 550 Posts
    Quote Originally Posted by jhuckaby View Post
    Hey guys,

    Here is a free, JavaScript / Flash library for offering copy-to-clipboard functionality in your web pages. It is fully compatible with Flash Player 10.

    http://code.google.com/p/zeroclipboard/

    Enjoy!

    - Joe
    thanks for the heads up!

    it's too bad that the code is 30X bigger an must be integrated into the page instead of the standalone cut and paste code i had...

    but hey; it's better than nothing, and it's nice to have the functionality back.

    maybey i could squeeze down the code and use a modal dialog to restore the cut and pastability...

    thanks again for the update!
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  • #10
    Regular Coder
    Join Date
    Jan 2009
    Posts
    156
    Thanks
    47
    Thanked 0 Times in 0 Posts

    Flash 10 Copy to Clipboard Script

    I found another copy to clipboard script that works with Flash 10:

    http://www.revivedwire.com/misc/scri...h_Flash_10.php

  • #11
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,184
    Thanks
    10
    Thanked 569 Times in 550 Posts
    Quote Originally Posted by Daniellez View Post
    I found another copy to clipboard script that works with Flash 10:

    http://www.revivedwire.com/misc/scri...h_Flash_10.php
    thanks for the link.
    This one is much smaller, it could all be worked into about 10kb.

    still, it demands a physical click on a visible flash movie, whereas the old one could fire from just JS in the background.

    Perhaps if it were worked into a showModalDialog routine, it could be very useful. I'm thinking a SMD popup that is as close to window.confirm() as possible, where the "ok" button runs the copy flash, and "cancel" closes the dialog.

    that way, it could be used without having to change any document html or css, virtually re-providing the same "script library function" appeal of the older version (plus an extra confirm click, which probably isn't a bad thing anyway).
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  • #12
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hello I created a script shaped bot automatically filled form
    as: http://allosky.com/index.php the destination a feedback form skyrock
    contact me: so-m3-poupey@hotmail.fr

  • #13
    Banned
    Join Date
    Jun 2007
    Location
    Web Designer
    Posts
    321
    Thanks
    0
    Thanked 6 Times in 6 Posts
    Quote Originally Posted by iAnissa View Post
    Hello I created a script shaped bot automatically filled form
    as: http://allosky.com/index.php the destination a feedback form skyrock
    contact me: removed
    In which programming language? what does the script do, better remove your email address from the post before moderator catches it.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •