Results 1 to 4 of 4

Thread: Javascript reload image

  1. #1
    Join Date
    Jan 2009
    Posts
    39

    Javascript reload image

    Hi guys,
    I want to reload a image using javascript, i know the way to reload the entire document but i only want to reload the image. Does some know how to do this?

  2. #2
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Javascript reload image

    Try the following code if does what you need:

    Code:
    <script type="text/javascript">
    function reloadImage(){
    if(document.images){
    document.images['imageName'].src = 'Image.jpg?' +
    Date.parse(new Date().toString());
    } setTimeout(reloadImage,5000);
    }
    </script>
    </head>
    
    <body onload="reloadImage()">
    <img name="imageName" src="Image.jpg">

  3. #3
    Join Date
    Mar 2008
    Posts
    198

    Re: Javascript reload image

    The animation stops if the user moves around the page with a link like the one at the bottom of this page. Experienced users can force a reload to get the images going again, but the following JavaScript function can be used to ensure they are automatically restarted:

    function reloadThePage() {
    document.images[0].src=""
    document.images[0].src="Dragon_Running.gif"
    }

    This is called by adding an onClick handler to FORM buttons or A anchor tags like this:

    onClick="reloadThePage()"



    See this page Javascript Reload Test

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Javascript reload image

    If you'll use your using setTimeout() , this will only change the image. You need to change the image and the attached link. You need to use setinterval() instead. And instead of having the setInterval() twice. Just use <body onload="clock()"> you alluded to), it will change the image and the link.

Similar Threads

  1. How to reload weapon in Serious Sam 3
    By Jasseen in forum Video Games
    Replies: 6
    Last Post: 05-10-2011, 10:59 AM
  2. How to keep rollover image onClick in javascript?
    By MAGALY in forum Software Development
    Replies: 4
    Last Post: 08-03-2010, 08:02 PM
  3. Change Image and Update two frames in Javascript
    By Sandy22 in forum Software Development
    Replies: 3
    Last Post: 10-12-2009, 03:24 AM
  4. How to create Javascript Image Rotation
    By abbase in forum Software Development
    Replies: 3
    Last Post: 31-10-2009, 01:48 PM
  5. Upload image randomly with JavaScript Page
    By Zubeen in forum Software Development
    Replies: 3
    Last Post: 25-02-2009, 02:54 PM

Tags for this Thread

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
  •  
Page generated in 1,714,229,779.94537 seconds with 17 queries