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 5 of 5
  1. #1
    New Coder
    Join Date
    Aug 2004
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Copy text by clicking on an anchor

    Can some one give me a sample code of a function, which can be attached to an anchor in order to copy the content of a div with a specific id.

  • #2
    Regular Coder
    Join Date
    May 2007
    Posts
    118
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Do you mean copy to clipboard? Then try this code..

    Code:
    <script>
    function CopyToClipboard(id){
    if (document.all)
    {
     window.clipboardData.clearData();
     window.clipboardData.setData('Text',document.getElementById(id).innerHTML);
    } else alert('It works only in IE');
    }
    </script>
    
    <div id="div1">hello world</div>
    <a href="Javascript:CopyToClipboard('div1');">Copy</a>
    Forum for webmasters and developers
    http://www.htmlfrenzy.com
    Are you an IT expert? Join our Reward system
    www.htmlfrenzy.com/reward-system.php

  • #3
    New Coder
    Join Date
    Aug 2004
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, thanks for the sample, but is it possible to have a function which will work for both IE and Firefox?

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Quote Originally Posted by soundreamer View Post
    Yes, thanks for the sample, but is it possible to have a function which will work for both IE and Firefox?
    yes, of course

    its here

  • #5
    New Coder
    Join Date
    Aug 2004
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you


  •  

    Posting Permissions

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