SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict
    Join Date
    Dec 2001
    Location
    Market Harborough, UK
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Forcing an image to refresh / reload

    Hi,

    I'm working on a staff / student management system which includes, on the details page for an individual, a photograph.

    If the user has appropriate rights, there is a button below this which, when clicked, opens a popup to allow a new photo to be uploaded.

    So far, so good. ANyway, once this has happened, I want the main page to re-load the image to show the new photograph. I would prefer it, however, if the whole page were not reloaded.

    Is there a method attached to an <img> tag which will cause it to re-load it's image from the server?

    Many thanks,
    Paul Simpson, BSc, MCNI, MCNE

  2. #2
    SitePoint Guru dale_burrell's Avatar
    Join Date
    Aug 2002
    Location
    Wellington, New Zealand
    Posts
    861
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Changing the src attribute on the image will cause the browser to reload the image.
    If you aren't living life on the edge
    - you're taking up too much space
    Creative Dreaming Ltd / Ask The Local / Amanzi Travel

  3. #3
    SitePoint Addict
    Join Date
    Dec 2001
    Location
    Market Harborough, UK
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, but the src isn't changing, only the image file on the server that the src points to.... If I simply change it and change it back, I get the cached image from the first visit

    Paul
    Paul Simpson, BSc, MCNI, MCNE

  4. #4
    SitePoint Guru dale_burrell's Avatar
    Join Date
    Aug 2002
    Location
    Wellington, New Zealand
    Posts
    861
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In that case try changing the src from e.g. image.jpg to image.jpg?v=2
    If you aren't living life on the edge
    - you're taking up too much space
    Creative Dreaming Ltd / Ask The Local / Amanzi Travel

  5. #5
    SitePoint Addict
    Join Date
    Dec 2001
    Location
    Market Harborough, UK
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahhh! I'll give it a go. Thanks
    Paul Simpson, BSc, MCNI, MCNE

  6. #6
    SitePoint Guru dale_burrell's Avatar
    Join Date
    Aug 2002
    Location
    Wellington, New Zealand
    Posts
    861
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So... did it work?
    If you aren't living life on the edge
    - you're taking up too much space
    Creative Dreaming Ltd / Ask The Local / Amanzi Travel

  7. #7
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://developer.irt.org/script/416.htm

    If you're using a form with <input type="file" /> in the pop-up - safe guess - have your server-side program return a document to the pop-up with this:
    Code:
    <script type="text/javascript">
    
    if (opener && !opener.closed)
    	if (el = opener.document.getElementById('img_id '))
            	el.src = el.src.split('?')[0] + '?' + new Date().getTime();
    	self.close();
    
    </script>
    ::: certified wild guess :::

  8. #8
    SitePoint Addict
    Join Date
    Dec 2001
    Location
    Market Harborough, UK
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you, one and all, for the suggestions!

    I can't actually test them yet because of a problem I've got with getting the file to upload - I've posted a question in the PHP forum about that one!
    Paul Simpson, BSc, MCNI, MCNE

  9. #9
    SitePoint Enthusiast ganesch's Avatar
    Join Date
    Feb 2004
    Location
    Zürich, Switzerland
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dale_burrell
    In that case try changing the src from e.g. image.jpg to image.jpg?v=2
    Works like a charm


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
  •