views:

233

answers:

3

Firefox (and other browsers i believe) stop gif animation when you click the Stop button or invoke it via the Escape key.

I have a text input that on change makes ajax requests to update other elements. As part of this ajaxyness i have an animated gif to show feedback.
I also trap the escape key press in this input so as to clear the text field for better UX.

My problem is after the escape key is pressed once, none of the ajax gifs animate anymore until the page is refreshed. Does anyone know a workaround?


Stuff i've tried:

I tried the e.stopPropagation(); and e.cancelBubble = true; in the function handling the e.keyCode == 27 and that didn't seem to work. I suspect that this stops trigging more js events and the browser catches the escape irrespective of js activity.

I have the gif showing/hiding via adding/removing a css class so it's difficult to apply the "change gif url to reset" workaround. I dont even know if this works anyway - didn't test it. But it seems difficult. If anyone knows that this works and knows of an easy way to apply the hack with background-image: url(../images/ajax-loader_dotcirclel13x13.gif); css then please let me know.

A: 

Hmm. Have you considered using a small "please wait" Flash animation instead?

Seriously. As far as a cursory test shows, Flash ignores the Esc key.

It might even be possible to import your animated GIF into a Flash movie. I don't know.

You could use JavaScript to create a non-flash fallback (showing the original animated GIF instead).

Pekka
Hey that might work. I'd guess the same that flash prob ignores the escape key. But i don't have any flash in my web app presently and i don't plan on adding any. Thanks for the suggestion tho.
cottsak
@cottsak yeah, I can understand not wanting to add that requirement. As a progressive enhancement (with a Fallback if it's not present), it would be okay though IMO.
Pekka
A: 

Okay, a second idea: Put the loading GIF into a separate HTML document and show it in a small IFRAME with no borders.

I have no idea whether it'll work, though. Chances are that the "Cancel" command is propagated to all child IFRAMEs too, so it might well not.

Pekka
Yeh i read about something like this too. I didn't mention this in the "Stuff i've tried" coz of the fact that i'm showing the image via css and not an `IMG` element. So i don't wanna go adding another container (or set of containers in the case of iframe) when my show/hide implementation is so simple already. I'm sure you understand.
cottsak
But dood, if you keep coming up with answers at this rate, i'll have it solved in no time :D
cottsak
@cottsak :) Well, I think those were my two best shots :)
Pekka
+2  A: 

Unfortunately you can't override the fact that the browser stops an animated gif when the ESC key is pressed. I would assume this is so that the user always has the ability to stop annoying animated gifs if they become too overwhelming (I'm not saying that your loading gif is annoying ;)). This page describes how they can be disabled all together in FF.

I would recommend using JavaScript to create a simple animation. You could even do it using a sprite with all of the frames from the gif animation and just moving the background-position around for each frame.

Alex