www.webdeveloper.com
Results 1 to 4 of 4

Thread: Force image update within a function

  1. #1
    Join Date
    Nov 2011
    Posts
    11

    Force image update within a function

    Hi,

    I need to show a gif in an image element until some process is done, so my function looks like:

    Code:
    function foo () {
    	var imgdst = document.getElementById ('myimgbox');
    	myimgbox.src = '/img/loading.gif';
    .
    .
    .
            myimgbox.src = file.name;
    }
    The problem is that the /img/loading.gif image is never shown, it seems like it weren't refreshed when set, but just when the function ends.

    So, is there anymanner to force the refresh of the image element inmediatetly after myimgbox.src = '/img/loading.gif' ????

    TIA,

  2. #2
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,268
    Two causes can disrupt the load of the image...

    - The change is made at the end of the script
    Code:
    // Interrupt the script to load the image
    function foo () {
    	var imgdst = document.getElementById ('myimgbox');
    	myimgbox.src = '/img/loading.gif';
    	setTimeout(bar,50);
    }
    function bar(){
    .
    .
            myimgbox.src = file.name;
    }
    - The file change but preserve his name
    Code:
    // A dummy url to force not using the cache
    myimgbox.src = '/img/loading.gif&'+new Date().getTime();

  3. #3
    Join Date
    Nov 2011
    Posts
    11

    Forget it

    Thanks by your answer and excuse me for making you spent your time.

    I have not changed nothing and now it is working as expected. May be some weird issue with firefox that has dissapear after closing and opening it again.

    Regards,

  4. #4
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    Are you sure things are correct, as it appears you are retrieving the img element but not useing it?

    Code:
    function foo () {
    	var imgdst = document.getElementById ('myimgbox');
    	myimgbox.src = '/img/loading.gif';
    .
    .
    .
            myimgbox.src = file.name;
    }
    Shouldn't you be referencing imgdst in all those positions?
    JavaScript: Learn | Validate | Compact | bionoid

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles