SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    doubleclick -> clipboard

    hey guys,

    Wondering if a JS guru can help me. I am looping througha list of images on a per user basis from PHP/Mysql. I want to create links on each one that when you double-click it gets copied to the clipboard. I imagine this is going to be tough to get Mac accessibility but that's crucial, particularly IE on Mac. I think Navigator on Mac is going to be about the same as Mozilla.

    I'll show you what I was trying to do. This isn't working though...there's nothing wrong with the PHP, by the way. I just can't get a javascript event to copy to clipboard on doubleclick to work...

    PHP Code:
                while($rows = mysql_fetch_array($getsql))
                    {
                    @extract($rows);
                    $filesize = @format_filesize("$path/".$bbuserinfo[username]."/$filename");

                ?>
                <tr>
                    <td class="tablebody" width="40"><img src="file.gif" alt="file.gif"></td>
                    <td class="tablebody" width="120">
                    <a href="<?php echo $_SERVER['PHP_SELF']; ?>?preview=<?php echo $id?>">
                    <?php echo $filename?></a></td>
                    <td class="tablebody" width="60"><?php echo $filesize?>KB</td>
                    <td class="tablebody" width="400"><a name="img<?php echo $id?>" href="#" ondblclick="javascript:window.clipboardData.setData("Text", this.innerText); alert("Code copied to the clipboard. You can paste it now.");"><?php echo "$url$filename"?></a></td>
                    <td class="tablebody"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?delid=<?php echo $id?>&userid=<?php echo $bbuserinfo[userid]; ?>">[delete]</a></td>
                </tr>
                <script language="Javascript">
    <!--
    document.img<?php echo $id?>.select();
    document.execCommand('Copy');
    //-->
    </script>
                <?php
                    
    }
                
    ?>
    Aaron Brazell
    Technosailor



  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you trying to copy the acutal image file to the clipboard? Uhh, I don't think so. The select() method isn't even valid for image objects. Only form controls, controlRanges and textRanges, for both of which an image's ALT value or nothing would be copied, to the best of my knowledge.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually I want to copy the url.

    it would be like http://www.domain.com/path/to/image.gif, and I want to copy it as [ img]http://www.domain.com/path/to/image.gif[/ img] (minus the spaces in the img tag. This way the link can be cut and paste into vb...

    Aaron
    Aaron Brazell
    Technosailor



  4. #4
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok. so is there any other options for this?
    Aaron Brazell
    Technosailor



  5. #5
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got this to work.
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <title>Copy to clipboard</title>
    
    <script type="text/javascript">
    
    function copySrc( s )
    {
    	var tr = document.body.createTextRange();
    	tr.findText( s.innerText );
    	tr.select();
    	tr.execCommand('Copy');
    }
    
    </script>
    
    </head>
    
    <body>
    
    <span style="cursor:hand" ondblclick="copySrc( this ); return false;">images/pic1.gif</span>
    <br />
    <span style="cursor:hand" ondblclick="copySrc( this ); return false;">images/pic2.gif</span>
    <br />
    <span style="cursor:hand" ondblclick="copySrc( this ); return false;">images/pic3.gif</span>
    <br />
    <input type="text" /> &amp;#171; paste here
    
    </body>
    </html>
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  6. #6
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sweet! I added an alert box so people know they were copying the data. It works beautifully. Thanks.

    Aaron
    Aaron Brazell
    Technosailor




Bookmarks

Posting Permissions

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