Results 1 to 2 of 2

Thread: Need Javascript to force an image refresh for Firefox

  1. #1
    Join Date
    May 2008
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Need Javascript to force an image refresh for Firefox

    I am using Matt Mullenweg's php random image rotator. There is an issue with the refresh due to cacheing on Firefox. A javascript solution was posted on his site, but I don't really know javascript and can't get it to work.

    This is the solution that was outlined:
    http://ma.tt/2003/05/a-better-image-...comment-445657

    Dave Achtemichuk | October 20th, 2007 @ 10:23 pm
    I work often with sites/pages that use server-side caching, so PhilMills’ solution above doesn’t work (as the random number that’s generated would get cached also!). In the past I’ve instead implemented the same approach, but in Javascript. I’m not sure if I can paste code here, so I’ll just explain how:
    • 1) Output your IMG tag as normal, or using the solution immediately above (this will ensure it still works if JavaScript is disabled)
    • 2) Give the IMG tag an HTML ID (such as ‘randimage’)
    • 3) Immediately after the IMG tag include some inline javascript ( using “script” tags … also within a CDATA comment if doctype is xhtml): “document.getElementById(’randimage’).src = document.getElementById(’randimage’).src + ‘?rand=’ + (Math.random() * 10000000);”
    • Hope this helps someone.
    Can someone please write this out for me? I'm unsure of what this is telling me to do.
    Last edited by jscheuer1; 06-13-2008 at 08:00 AM. Reason: fix smily icon

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Well, the use of a random number isn't the best idea, those can repeat. A number generated by the Date object would be a better choice, it's constantly updated and never repeats. This is the sort of code described in your post, only using the Date object instead of the Math object's random function to generate a unique query:

    Code:
    <img src="whatever.jpg" id="some_id">
    <script type="text/javascript">
    document.getElementById('some_id').src = document.getElementById('some_id').src + '?unique=' + new Date().valueOf();
    </script>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    ange (06-13-2008)

Similar Threads

  1. Javascript code for text & image scroller works in Firefox but not IE
    By tmorelli in forum Dynamic Drive scripts help
    Replies: 7
    Last Post: 03-26-2013, 07:53 PM
  2. Resolved Force link to download image not open
    By davelf in forum HTML
    Replies: 6
    Last Post: 05-31-2012, 03:17 AM
  3. Replies: 4
    Last Post: 05-14-2008, 09:19 AM
  4. Replies: 4
    Last Post: 03-09-2007, 04:30 PM
  5. Replies: 6
    Last Post: 01-14-2006, 06:40 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
  •