Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2007
    Thanked 0 Times in 0 Posts

    Question Force automatic image reload onload.

    Hi guys, I'm not too familiar with Javascipt and in fact had attempted to solve this problem with PHP initially. Here is my objective:

    I want to have a page that constantly reloads an image as soon as it's loaded. I understand I can make the image seem "new" to the client by adding on a variable such as image.gif?num=i (Within a for loop with variable i) but I am not sure how I can get it to initially load the image, wait until it is loaded, and then once it is reloaded empty the contents of the DIV it is in and reload the image again with a new ?num.

    Could someone help me out with this?

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Thanked 16 Times in 15 Posts
    Something like this should work:
    <script type="text/javascript">
    var imgfile = 'http://www.somewhere.com/images/pic.jpg';
    function dejaView() {
    var now = new Date();
    var i = now.getTime();
    myImage = new Image();
    myImage.src = imgfile+'?'+i;
    function ckLoad() {
    if (myImage.complete) {
    document.getElementById('myimg').innerHTML='<img src="'+myImage.src+'" alt="" title="" />';
    dejaView(); }
    else { setTimeout('ckLoad()', 100); }
    <div id="myimg"> </div>


    Posting Permissions

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