Results 1 to 9 of 9

Thread: refresh image (javascript)

  1. #1
    chenko
    Guest

    refresh image (javascript)

    I got some code to refresh a image at certain time intervals, but it dosent seam to refresh the picture with the new one??

    this is my code ... thanks

    Code:
    <HTML><BODY>
    
    <!-- visionGS Script Code Begin --> 
    <SCRIPT language="JavaScript" type="text/javascript">
    var t = 5 // interval in seconds
    image = "image.jpg" //name of the image 
    
    function Start() {
    tmp = new Date();
    tmp = "?"+tmp.getTime()
    document.images["visiongs"].src = image+tmp
    setTimeout("Start()", t*1000)
    }
    </SCRIPT> 
    <!-- visionGS Script Code End --> 
    
    <IMG src=image.jpg border=1 name="visiongs">
    </BODY>
    </HTML>

  2. #2
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    what i dont understand is:

    image+tmp

    form what i see it would be something like:

    image.jpg?8:31:12

    this can't be an image src, or if it can what it does??

  3. #3
    chenko
    Guest
    more like image.jpg?3412351

    its a random number so caching dont cause a problem.

  4. #4
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340
    Here, i made this a while ago. It probably has some stuff you don't need in there, but it gets the job done.

    Tell me if you have any questions.

    Code:
    <html>
    <head>
    
    <title>Ad Cycle</title>
    
    <script language="javascript">
    
    <!--
    
    	// Checks for Inetrnet Explorer or Netscape
    	var IE = (document.all)? 1 : 0;  
    	var NS = (document.layers)? 1: 0;
    
    	
    	var i = 0;
    	var j = 3; // Number of images and URL's used
    	var tmrSpeed = 1000; // Sets rotation speed
    
    	// Array of image sources
    	var srcarr = new Array(
    	"img1.gif",
    	"img2.gif",
    	"img3.gif"
    	);
    
    	// Array of link URL's
    	var urlarr = new Array(
    	"http://www.ask.com",
    	"http://www.google.com",
    	"http://www.cnet.com"
    	);
    
    // Begin main function body
    
    function update(){
    
      if (i >= j) {i = 0}; 
      if (i >= j) {i = 0};
    
    	var src = srcarr[i];
    	var url = urlarr[i];
    	var hoverText = " ";    // Text shown in the window status 
    				// bar on image hover. Note: set
    				// hoverText equal to "url" without the
    				// "" to display the url of the current link.
    
    	var mouseOver = "window.status='"+hoverText+"';return true;";
    	var mouseOut = "window.status=' ';";
    
    imglink = '<a href='+url+' onMouseover="'+mouseOver+'" onMouseout="'+mouseOut+'"><img border=0 src='+src+'></a>';
    
    // Write the new link to "obj1"
    if (NS) {document.obj1.document.write(imglink);document.obj1.document.close();}
    else {obj1.innerHTML = imglink;};
    
    i++;
    
    setTimeout("update()", tmrSpeed);
    
    }
    
    //-->
    
    </script>
    
    </head>
    
    <body onLoad="update()">
    
    <div id="obj1" style="position:absolute">Loading Image Cycle...</div>
    
    </body>
    
    </html>

    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA

  5. #5
    chenko
    Guest
    errmm, why are there 3 image paths?!?!

  6. #6
    scoutt
    Guest

    Re: refresh image (javascript)

    Originally posted by chenko

    Code:
    <HTML><BODY>
    
    <!-- visionGS Script Code Begin --> 
    <SCRIPT language="JavaScript" type="text/javascript">
    var t = 5 // interval in seconds
    image = "image.jpg" //name of the image 
    
    function Start() {
    tmp = new Date();
    tmp = "?"+tmp.getTime()
    document.images["visiongs"].src = image+tmp
    setTimeout("Start()", t*1000)
    }
    </SCRIPT> 
    <!-- visionGS Script Code End --> 
    
    <IMG src=image.jpg border=1 name="visiongs">
    </BODY>
    </HTML>
    would it be because you have the same name for the image.

  7. #7
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340
    Originally posted by chenko
    errmm, why are there 3 image paths?!?!
    Like i said, i wrote it a long time ago for one of my friends. The part that isin't working in yours, works in mine, so i thought that you might be able to use it.

    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA

  8. #8
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340
    good idea

    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA

  9. #9
    chenko
    Guest

    Re: Re: refresh image (javascript)

    Originally posted by scoutt

    would it be because you have the same name for the image.
    because the image is updated on the server... It is being used for a web cam, and i dont want to repeatively update the whole page...

    the page the code is on is at http://frankhdale.demon.co.uk/cam/default.asp
    this is the exact code that came from the visionGS software im using for my webcam.

    sebs: thanks, i will try that when im back at work monday, thou i might do it in the week if i can be bothered

Posting Permissions

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



Click Here to Expand Forum to Full Width