/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] ie animated gif freeze til page loads

Hello,

I am having a problem, I am using an animated gif to show the progress of an upload on my site. The animated gif is basically there to let people know that the file is being uploaded, even though it has nothing to do with the progress.

So here is what happens, the form page loads and the progress bar image is hidden (using CSS). The user then clicks submit and (by using javascript/ CSS) the form is hidden and the display for the image is changed to display (not the acutal image but the iframe that it is in). While the file is being uploaded (all on the same page).

In firefox, netscape, opera, the animated gif continues to run and show the progress bar after the user clicks submit; there are no pauses in the animation. But in internet explorer, the animation pauses until the page is finished uploading the file from the form.

Does anyone know a reason for this? I may have posted in the wrong thread but I figured graphics section might help. Any suggestions?

Thanks

to post a comment

28 Comments(s)

Copy linkTweet thisAlerts:
@pcthugJan 05.2006 — Well i pretty sure that it's not the actual .gif thats the problem, but rather some of your coding. Wheter it is some css that isnt IE standard, or you have made a mistake in your JS. Maybe a link might help?
Copy linkTweet thisAlerts:
@barksterFeb 14.2006 — I'm trying to do the same thing with CSS to unhide an animated gif and mine does the same thing. It animates for a second then when the upload begins it kills the animation. Let me know if you figure something out.
Copy linkTweet thisAlerts:
@guoxiangjingMar 27.2006 — I have the similar problem, and I don't know the reason but I do resolve the problem.

I write the following code at the very beginning. And I encounter the problem you mentioned.

[B]<html>

<head>

<title>test progress bar.</title>

</head>

<body onbeforeunload="document.getElementById('progressbar').style.display = '';">

<span id="progressbar" style="display: 'none'">

<img src="loading.gif" />

</span>

<a href="http://www.sina.com.cn">sdflj</a>

</body>

<script language="JavaScript">

document.getElementById("progressbar").style.display = 'none';

</script>

</html>[/B]


Then I rewrite the code to be:

[B]<html>

<head>

<title>test progress bar.</title>

</head>

<body onbeforeunload="document.getElementById('progressbar').style.display = '';">

<span id="progressbar" style="display: 'none'">

<table width="100%" height="100%">

<tr><td align="center" valign="middle">

<table width="83">

<tr><td background="loading.gif">&nbsp;</td></tr>

</table></td>

</tr>

</table>

</span>

<a href="http://www.sina.com.cn">sdflj</a>

</body>

<script language="JavaScript">

document.getElementById("progressbar").style.display = 'none';

</script>

</html>[/B]


The animated gif works now.

Hope this solution is useful.
Copy linkTweet thisAlerts:
@mididelightauthorMar 27.2006 — That is great, I Will have to try that code. So that onbeforeunload event handler works only in IE. Does this script work in Firefox?
Copy linkTweet thisAlerts:
@barksterMar 27.2006 — Can't wait to try it, thanks
Copy linkTweet thisAlerts:
@guoxiangjingMar 28.2006 — This code works in both Internet Explorer 6.0 and firefox 1.5.0.1. I can't guarantee it is still working if you are using old version of that browsers.
Copy linkTweet thisAlerts:
@miketuxJul 11.2007 — I've tried the td background solution, but still have the same problem just in IE7.

Before somebody tell me that turn on the multimedia->animated gif parameter, I've already activated.

Does anybody have the same problem? or better: a solution?

Thanx.

miketux
Copy linkTweet thisAlerts:
@akgiddingsJul 20.2007 — I haven't seen this anywhere else so I thought I would put it out there.

The way I did it was as follows - Put the gif out there in the page with visibility:hidden

[COLOR="SeaGreen"]<img id="imgShowWaitMsg" style="visibility:hidden;" src="imageswait30tr.gif" width="30" height="30" border="0" />[/COLOR]

Then when from the onsubmit javascript routine, call

[COLOR="SeaGreen"]window.setTimeout(ReallyTurnMeOnPlease, 500);[/COLOR]

ReallyTurnMeOnPlease is defined as follows:

[COLOR="SeaGreen"]var ReallyTurnMeOnPlease = function ()

{

// Have to turn on the animated gif in here to get around an IE problem where it won't run on submit.

var dd = document.getElementById("imgShowWaitMsg");

if(typeof (dd) == 'object')

{

dd.style.visibility = "visible";

};

}[/COLOR]


This seems to delay the gif long enough so it's thread is not stopped by the submit.
Copy linkTweet thisAlerts:
@miketuxJul 20.2007 — Didn't work for me.

I think I have to avoid animated gifs :mad:

Thank you anyway.
Copy linkTweet thisAlerts:
@ElteSep 05.2007 — Hi guys, I have found another solution that seems to work in both Firefox 2 and IE7. The trick is to load the animated gif after the form is submitted. Javascript functions:

<script>

function loadSubmit() {

document.getElementById('form_fields').style.display = 'none';

document.getElementById('pleasewait').style.display = 'block';

document.getElementById('pleasewait').style.backgroundImage = 'url(/images/loading.gif)';

}

</script>

HTML (the upload-image size is 225*15):

<div id="form_fields">

<form method="post" action="blah.php" onsubmit="return loadSubmit();">

<input type="fieldone" />>

<input type="submit" />

</form>

</div>

<div id="pleasewait" style="width:225; height:40; background-repeat:no-repeat; background-position:bottom;">

Uploading...

</div>
Copy linkTweet thisAlerts:
@soarchristMar 13.2008 — I found an even better solution to your problems... though this thread is probably too old for anyone to be checking still.

My animated gift would stop working also... even in firefox. I chose to not use a submit button through the form like i would normally. Instead, I use a input type='button' and have it run a script that shows the loading image... then submits the form. You have to have a double catch.

Here's my code and it magically works in IE7 and Firefox 2. Notice that the button invokes the showLoader() functions and so does the onSubmit call from the form. This makes the page ASSURE itself the image is shown.

[CODE]<script language="javascript">

function showLoader() {

document.upload_form.submitform.disabled = true;
document.getElementById("uploader_image").innerHTML = "Please wait...<br><img src='../../images/loading.gif'>";

}
function submitForm() {
document.upload_form.submit();
}
</script>

<p><form name="upload_form" action="upload_doc_post.php" enctype="multipart/form-data" method="post" onSubmit="showLoader();">
Give your file a title:<br>
<input type="text" name="name" size="25" style="height:25px; font-size:22px;"></p>
<p>Your file:
<input type="file" name="uploadfile" size="65"></p>
<p><input type="button" name="submitform" value="Upload File" onClick="submitForm(); showLoader();">
</form></p>
<div id="uploader_image" style="width:90%; height:50px; ">&nbsp;</div>[/CODE]
Copy linkTweet thisAlerts:
@mididelightauthorMar 13.2008 — surprisingly, i still get email about this thread.

Thanks for the suggestion. Maybe that can be used in some future projects I have coming up.
Copy linkTweet thisAlerts:
@willardnessMar 31.2008 — SOARCHRIST,

I just started using your scirpt for the showlaoder function - It works great on its own.

However, It now screws up my form validation JS. Do you know how integrate form validation along withe you showloader function?

Currently, the showloader function seems to submit the form and bypass my validation js script

Thanks!
Copy linkTweet thisAlerts:
@mididelightauthorMar 31.2008 — You probably need to create a function that encapsulates the showloader() and validate() function. Then onsubmit of the form, you call your new function, which then runs the validate function. once that checks out, your show loader function is fired and then finally the submit form functions.
Copy linkTweet thisAlerts:
@jeffsheadJan 17.2009 — I found an even better solution to your problems... though this thread is probably too old for anyone to be checking still.

My animated gift would stop working also... even in firefox. I chose to not use a submit button through the form like i would normally. Instead, I use a input type='button' and have it run a script that shows the loading image... then submits the form. You have to have a double catch.

Here's my code and it magically works in IE7 and Firefox 2. Notice that the button invokes the showLoader() functions and so does the onSubmit call from the form. This makes the page ASSURE itself the image is shown.

[CODE]<script language="javascript">

function showLoader() {

document.upload_form.submitform.disabled = true;
document.getElementById("uploader_image").innerHTML = "Please wait...<br><img src='../../images/loading.gif'>";

}
function submitForm() {
document.upload_form.submit();
}
</script>

<p><form name="upload_form" action="upload_doc_post.php" enctype="multipart/form-data" method="post" onSubmit="showLoader();">
Give your file a title:<br>
<input type="text" name="name" size="25" style="height:25px; font-size:22px;"></p>
<p>Your file:
<input type="file" name="uploadfile" size="65"></p>
<p><input type="button" name="submitform" value="Upload File" onClick="submitForm(); showLoader();">
</form></p>
<div id="uploader_image" style="width:90%; height:50px; ">&nbsp;</div>[/CODE]
[/QUOTE]


I tested this with IE7 and FF3. Works in both, but when pushing the enter button to submit the form, neither browser displays the image. If the button was used to submit the form previously, the image is displayed on subsequent submissions that are done by using the enter button. Even after refreshing the page, the image will display on submissions that are done with the enter button. You have to close the browser and go back to the page to recreate this issue.

[B]Anyone know how to add the “enter button” functionality for both browsers?[/B]

I thought [I]'onSubmit="showLoader();'[/I] in the form tag was supposed to do that ?
Copy linkTweet thisAlerts:
@mididelightauthorJan 21.2009 — You probably need to attach an event listener to the <enter> key that fires the showLoader and submitForm functions. For some reason the enter key may not fire it without it. Although, I have no research to back this up.
Copy linkTweet thisAlerts:
@snaglerFeb 17.2009 — I have yet another solution for this problem. It entails re-establishing the parent node of the containing block for the gif.

Here is an example. This is the containing block for the gif.

<div style="display:none">

<img id="progress" src="/images/snake_transparent.gif" alt=""/>

</div>

In your onsubmit() handler make sure you do this.

<input type="button" value="Upload" onclick="document.form.submit(); document.getElementById('progress').parentNode.style.display = 'block';">

Notice the use of parentNode. It's really simple. Give it a try.
Copy linkTweet thisAlerts:
@jeffsheadFeb 17.2009 — I have yet another solution for this problem. It entails re-establishing the parent node of the containing block for the gif.

Here is an example. This is the containing block for the gif.

<div style="display:none">

<img id="progress" src="/images/snake_transparent.gif" alt=""/>

</div>

In your onsubmit() handler make sure you do this.

<input type="button" value="Upload" onclick="document.form.submit(); document.getElementById('progress').parentNode.style.display = 'block';">

Notice the use of parentNode. It's really simple. Give it a try.[/QUOTE]


I tested the sample above and it appears to work, but I went a slightly different direction in which I want the submit button to be replaced by the gif.

This is what I have so far, but as you can see, I use text to replace the submit button instead of a gif:

[code=html]
<table>
<form id="form" action="" onsubmit="document.getElementById('submit').innerHTML='<div style='color:#666666;'>Please Wait...</div>'; document.getElementById('pass').innerHTML='<div>Password:</div>';" method="post">
<tr>
<td id="pass">
<div style="color:#FF0000;font-weight:bold;">Password:</div>
<div style="color:#FF0000;">is invalid!&nbsp;&nbsp;</div>
</td>
<td><input type="password" name="psword" /></td>
<td id="submit"><input type="submit" id="submit" name="submit" value="Login" /></td>
</tr>
</form>
</table>
[/code]


My sample above works just fine, but I still would like to replace the "Please wait..." text with a gif. When I replace the text with a gif, I get the same problem of it not animating as in previous samples.

Any ideas?
Copy linkTweet thisAlerts:
@snaglerFeb 17.2009 — OK. I think I have it.

You have to capture the onsubmit() event in order for this to work. That means you can't use the onsubmit event on the form tag. Also, change the input type="submit" to type="button".

You should be able to copy and paste this code "as is" and see it work in IE.

[CODE]<table>
<form id="form" action="" method="post">
<tr>
<td id="pass">
<div style="color:#FF0000;font-weight:bold;">Password:</div>
<div style="color:#FF0000;">is invalid!&nbsp;&nbsp;</div>
</td>
<td><input type="password" name="psword" /></td>
<td id="submit">
<input type="button" name="submit" value="Login" onclick="document.form.submit();

document.getElementById('prog').parentNode.style.display = 'block'; [[COLOR="Red"]make sure this goes before the next code or it won't work in IE[/COLOR]]
document.getElementById('pass').innerHTML='<div>Password:</div>';
document.getElementById('submit').innerHTML='';"/></td>
<td>
<div style="display:none;">
<img id="prog" src="/images/snake_transparent.gif" alt=""/> [[COLOR="Red"]replace with your gif[/COLOR]]
</div></td>
</tr>
</form>
</table>[/CODE]
Copy linkTweet thisAlerts:
@jeffsheadFeb 20.2009 — I just found time to test. Does not work in IE7 or FF3. IE gives the following error:

'document.form' is null or not an object

I even changed the id of the form from 'form' to 'form1'. Did not help. I then added name="form1" to the form tag and the error changed to:

object doesn't support this property or method

Correct me if I am wrong, but since this uses an onclick event, it will not work if the user hits the enter key instead of clicking on the button. Is there any way around that?
Copy linkTweet thisAlerts:
@snaglerMar 05.2009 — Hi Jeffshead,

Sorry I took so long to get back.

I redid the whole thing. You should be able to copy this into a test.html file and see it run in Firefox and IE.

There seems to be a problem with animating a gif in IE in a table cell that I just can't figure out. To that end, I made two versions - one with tables and one with divs. The div version animates okay in IE but the table version doesn't.

Also, I added in a keyboard function for capturing the ENTER key (key code 13) so pressing the ENTER key works too.

You will have to enter a url for the "action" attribute:
[code=html]<form name="form2" action="" method="post">[/code]

You have to put in your own gif url too.
[code=html]<img id="prog" src="/images/snake_transparent.gif" alt=""/>[/code]

Give it a try and let me know if it works for you.

[code=html]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml" lang = "en">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>

<script type="text/javascript">
//<![CDATA[
function submit1(){
document.form.submit();
document.getElementById('prog').parentNode.style.display = 'block';
document.getElementById('pass').innerHTML='<div>Password: </div>';
document.getElementById('submit').innerHTML='';
return false;
}

function checkEnterKey(e){

if (e.keyCode == 13) {
submit1();
return false;
}
}

//]]>
</script>
<div>Table Version</div>
<form name="form" action="" method="post">
<table>
<tr>
<td id="pass">
<div style="color:#FF0000;font-weight:bold;">
Password:
</div>
<div style="color:#FF0000;">
is invalid!&nbsp;&nbsp;
</div>
</td>
<td>
<input type="password" name="psword" onkeydown="checkEnterKey(event)"/>
</td>
<td id="submit">
<input type="button" name="button" value="Login" onclick="submit1()"/>
</td>
</tr>
<tr>
<td>
<div style="display:none;">
<img id="prog" src="/images/snake_transparent.gif" alt=""/>
</div>
</td>
</tr>
</table>
</form>
<script type="text/javascript">
//<![CDATA[
function submit2(){
document.form2.submit();
document.getElementById('prog2').parentNode.style.display = 'inline';
document.getElementById('pass2').innerHTML='<div>Password: </div>';
document.getElementById('submit2').innerHTML='';
}

function checkEnterKey2(e){

if (e.keyCode == 13) {
submit2();
return false;
}
}

//]]>
</script>
<hr/>
<div>Div version</div>
<form name="form2" action="" method="post">
<div id="pass2">
<div style="color:#FF0000;font-weight:bold;">
Password:
</div>
<div style="color:#FF0000;">
is invalid!&nbsp;&nbsp;
</div>
</div>
<div>
<input type="password" name="psword" onkeydown="return checkEnterKey2(event)"/>
</div>
<div id="submit2">
<input type="button" name="button" value="Login" onclick="submit2()"/>
</div>
<div style="display:none;">
<img id="prog2" src="/images/snake_transparent.gif" alt=""/>
</div>
</form>
</body>
</html>[/code]
Copy linkTweet thisAlerts:
@jeffsheadMar 06.2009 — Thanks snagler. No need to apologize. Any and all help is appreciated.

I gave it a quick test, but the action happens so quickly that there is not enough time to see if the GIF is animated. Is there a way to slow down the action so I can see if the gif is animated?
Copy linkTweet thisAlerts:
@snaglerMar 06.2009 — Yes. You can put a delay in your server code. I'm using PHP so I added this line in my action script like this:

[CODE]<?php
// Add two second delay before returning.
sleep(2);

// Redirect back to original page. "test.html" is my originating page.
header("location: http://" . $_SERVER['SERVER_NAME'] . '/test.html' );
?>[/CODE]


Of course you have to put the url for the script in the "action" attribute of the <form> tag. There are two of them
[code=html]<form name="form" action="yourscript.php" method="post">
<form name="form2" action="yourscript.php" method="post">[/code]
Copy linkTweet thisAlerts:
@snaglerMar 12.2009 — Here is a link that describes some of these techniques.

http://www.christorian.com/dhtml/html.php?dhtmlpage=uploadButtonOverlay-1
Copy linkTweet thisAlerts:
@phantomstiMar 21.2009 — Thanks Snag for those code samples, it really helped out. Everything works very well for me, but the only thing that doesn't work is if I attach a verify field script into the mix the the submit2() function no longer works.

So, for example onclick="return verify('RequestForm'); submit2();" will only launch the required field checker, and not the submit2() function. What's the best way to tackle this situation? I was thinking about adding something to the submit2() function that would automatically check to see if it could verify that all required fields have information in them before executing the form submission portion of the code.

Any ideas would be really helpful!
Copy linkTweet thisAlerts:
@snaglerMar 22.2009 — The best way to handle this, phantomsti, is to place all your verifying code within the submit2() function. Just make sure the verifying code comes before the submit() call. Give it a try and let me know.
Copy linkTweet thisAlerts:
@PakaMay 12.2009 — Your onclick handler is returning the result of the first function:

<code>onclick="return verify('RequestForm'); submit2();"</code>

change it to:

<code>onclick="verify('RequestForm'); return submit2();"</code>
Copy linkTweet thisAlerts:
@nasim007Jun 16.2009 — Hello everyone,

Quick question, here is a very small piece of code:


*************************
<html>

<head>

<title>Untitled</title>

</head>

<body>

<p align="center"><img src="AnimationWizard1.gif" name="btest" style="border:solid 1px red"></p>

<script language="VBScript" type="text/vbscript">

Set oWSHShell = CreateObject("WScript.Shell")

Set oWSHFSO = CreateObject("Scripting.FileSystemObject") '

MsgBox "Start"

oWSHShell.Run "c:testrobocopy c: c:_devtemp *.* /e /L /X /V", 0, true

MsgBox "Done"

</script>

</body>

</html>

*********************************

Why does the gif freeze upon initializing the dialog box?
×

Success!

Help @mididelight spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...