+ Reply to Thread
Results 1 to 8 of 8

Thread: Refresh image on click not working as planned...

  1. #1
    Barn Regular bryceowen is on a distinguished road bryceowen's Avatar
    Join Date
    Sep 2008
    Location
    Jacksonville, FL
    Posts
    93
    Rep Power
    4

    Refresh image on click not working as planned...

    So I'm trying to refresh an image when it's clicked, but I've a small problem...

    Here's the snippet I'm using:
    Code:
    onclick="document.getElementById('weather').src='http://sirocco.accuweather.com/nx_mosaic_160x120_public/sir/inmsirfl_.gif?rand='+Math.random();"
    
    This is attached to the IMG tag I'm using. When the page first loads, the image displays just like I want it to, but when I click the image to refresh it, I get a broken image. I'm assuming it has something to do with the way accuweather stores their images because if I try to copy/paste the link of the 'refreshed' image, I get a 404 page. If I try the code WITHOUT the "?rand=+Math.random()", the image doesn't refresh (natrually, as the computer has no reason to reload something in cache). Is there a javascript solution that would perhaps delete the existing image from the cache and then re-download it?

  2. #2
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    Caching is done by the user's browser. You could add some server-side code to prevent the page from being cached, but not sure if that's what you're looking for. I've also seen the technique you're using (where a timestamp is added as a querystring parameter, but I'm not sure why it's not working in this case.
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  3. #3
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Can you post the whole <img /> tag code?

  4. #4
    Barn Regular bryceowen is on a distinguished road bryceowen's Avatar
    Join Date
    Sep 2008
    Location
    Jacksonville, FL
    Posts
    93
    Rep Power
    4

    Here's the line I was trying to use (I've substituted an iframe [wretch] for the time being):
    Code:
    <img src="http://sirocco.accuweather.com/nx_mosaic_160x120_public/sir/inmsirfl_.gif" onclick="document.getElementById('weather').src='http://sirocco.accuweather.com/nx_mosaic_160x120_public/sir/inmsirfl_.gif?rand='+Math.random();" />
    

  5. #5
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    You never set the ID attribute of the image tag.
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  6. #6
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    Also, I just did a quick test and browsed to this url: AccuWeather.com

    They seem to be blocking this behavior with some type of .htaccess file or something in IIS, depending on the web server.
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  7. #7
    Barn Regular bryceowen is on a distinguished road bryceowen's Avatar
    Join Date
    Sep 2008
    Location
    Jacksonville, FL
    Posts
    93
    Rep Power
    4

    Oops! Yeah, I forgot to copy the ID tag over, but it was there in my original code.

    So it's a problem with access to the image through AccuWeather, eh? I guess I'll have to find another source for a radar map.

    Thanks, guys!

  8. #8
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    Either that or do as I suggested in post #2 regarding adding the appropriate headers to the page so that it is not cached in the browser.
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


+ Reply to Thread

Similar Threads

  1. SP not working!
    By Centurion in forum ASP Development
    Replies: 1
    Last Post: July 9th, 2009, 06:54 AM
  2. click on paging link page is redirecting
    By guddu in forum .NET Development
    Replies: 9
    Last Post: January 16th, 2009, 10:13 AM
  3. VBA Code on an On Click Event Procedure
    By CushingMT in forum Microsoft Access
    Replies: 5
    Last Post: December 18th, 2008, 08:05 AM
  4. Refresh a page without changing any value
    By PhloooooIsFlo in forum JavaScript Programming
    Replies: 14
    Last Post: November 12th, 2008, 05:22 PM
  5. adding refresh button to shout box
    By Shadow Wizard in forum Community Support, Suggestions & Feedback
    Replies: 7
    Last Post: July 14th, 2008, 12:06 PM

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

SEO by vBSEO