Results 1 to 3 of 3
  1. #1
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have standard image tags in an HTML document and I'm wanting a javascript onClick command to copy the image (local - not full path) URL to the clipboard. For instance, when the picture referenced by this:
    Code:
    [img]my.gif[/img]
    is clicked, the text "my.gif" go to the clipboard. Sounds simple enough, but I can't find appropriate code anywhere.

    Alan

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    [quote name='AlanMiller' post='789231' date='16-Aug-2009 06:58']I have standard image tags in an HTML document and I'm wanting a javascript onClick command to copy the image (local - not full path) URL to the clipboard. For instance, when the picture referenced by this:
    Code:
    [img]my.gif[/img]
    is clicked, the text "my.gif" go to the clipboard.[/quote]
    First, what I am about to write works only in IE. Mozilla browsers have a different security model (the clipboard is off limits) and a slightly different DOM.

    This retrieves the full path, which is not exactly what is written in the tag:
    Code:
    [img]my.gif[/img]
    This doesn't yield a completely clean string, but it's a start:
    Code:
    [img]my.gif[/img]

  3. #3
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='jscher2000' post='789262' date='17-Aug-2009 10:33']First, what I am about to write works only in IE. Mozilla browsers have a different security model (the clipboard is off limits) and a slightly different DOM.
    <snip>[/quote]

    Thanks Jefferson. I realized that my prehistoric HTML was a bit limiting here and I since discovered the name and id attributes. There are numerous pictures per page (should have said that) so I can generate the HTML with appropriate tags for each image, then just copy the value of the tag to clipboard.

    Alan

Posting Permissions

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