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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Static Gif To OnClick Gif With Link

    I'm looking for a simple code to perform this function I'm 3/4 of the way there but need some help.

    I have a static GIF that is swapped for an animated gif after an onclick event. I want the animated gif to have a clickable URL that is activated once the user clicks on the static GIF.

    Here is the current code I have to show the animated gif from the onclick event, how do I add a web site URL to make the animated.gif a clickable image link?

    Code:
    <img src="static.gif" width="620" height="549" onclick='javascript:(this.src=="static.gif"?this.src="animated.gif":"")' /></a>

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,065
    Thanks
    36
    Thanked 497 Times in 491 Posts
    If you want a solution, why not provide the static and animated GIF files to test with?
    Also, what the the URL you wish to go to when the animated GIF is visible?

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,028
    Thanks
    75
    Thanked 4,325 Times in 4,291 Posts
    Why not do this?
    Code:
    <img src="static.gif" width="620" height="549" 
         onclick="if ( this.src.indexOf('static') >= 0 ) { this.src='animated.gif'; } 
                  else { location.href='somePage.html'; } " />
    You should NOT test for this.src=='static.gif' because some browsers will replace your src with the full URL to the image (e.g., "http://www.yoursite.com/static.gif"). By just looking to see if "static" is part of the image.src, you avoid problems.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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