FireFox Never Stops Loading With iFrame Submission

Posted August 27, 2008 at 9:40 AM by Ben Nadel

Tags: ColdFusion, Javascript / DHTML

A while back, I created an AJAX file upload demo using jQuery and ColdFusion. The demo worked quite nicely, but people using FireFox 3 were telling me that FireFox never stopped loading. That is, the page would execute fine, but the window would signal (via the Status Bar and loading circle) that it never completed loading the page. Based on some feedback from Josh, I narrowed the problem down to the removal of the iFrame from the page during its own load callback:

  • jFrame.load(
  • function( objEvent ){
  • ..... CODE TO PROCESS .....
  •  
  • // Remove iFrame from page.
  • jFrame.remove();
  • }
  • );

Something about removing the iFrame as part of the its own load() event binding was causing issues. To get around this, all I had to do was add a slight delay to the actual removal of the iFrame:

  • jFrame.load(
  • function( objEvent ){
  • ..... CODE TO PROCESS .....
  •  
  • // Remove the iFrame from the document.
  • // Because FireFox has some issues with
  • // "Infinite thinking", let's put a small
  • // delay on the frame removal.
  • setTimeout(
  • function(){
  • jFrame.remove();
  • },
  • 100
  • );
  • }
  • );

By delaying the iFrame removal for a tenth of a second (could have been smaller), it seems to allow the load() event to execute properly without causing any hanging on the page. FireFox acknowledges that the iFrame has in fact stopped loading once the load() event has finished executing. Then, once it's done executing, we can then safely remove the iFrame from the page.

I am sure that there are a number of scenarios that would cause FireFox to never stop loading, but this is a solution to one of them.


You Might Also Be Interested In:



Reader Comments

Aug 27, 2008 at 10:41 AM // reply »
153 Comments

I've gotten to the point in my code where absolutely any removal of a DOM object is done asynchronously. Too many browsers do strange things where you remove an object and it is in any way tied via an event to the code you are currently running.

Yeah, it's paranoia. Yeah, it's cargo cult. But as the example above shows, it's a line or two of code that prevents hours of debugging headaches.


Aug 27, 2008 at 11:01 AM // reply »
11,246 Comments

@Rick,

Better to be paranoid than have to exhaustively test on every browser and version ever made :) I like your style.


Aug 28, 2008 at 3:19 AM // reply »
1 Comments

"Based on some feedback from Josh, I narrowed the problem down to the removal of the iFrame from the page during its own load callback"

Doctor, I think this man has Apple Fever. ;)


Aug 28, 2008 at 8:13 AM // reply »
11,246 Comments

@Craig,

Ha ha :) Good catch.


Dec 6, 2008 at 1:53 PM // reply »
1 Comments

Thank you a lot! Simple and clean! :D


Jan 2, 2009 at 4:39 PM // reply »
1 Comments

Thanks a bunch! This also saved my day!


Oct 27, 2009 at 9:45 PM // reply »
1 Comments

Worked like a charm! Thanks! I was wondering what was going on with the constantly loading Firefox tab.

Great transaction, great seller, would recommend (A+++).


Nov 26, 2009 at 4:36 PM // reply »
1 Comments

I think it's difficult for FF to remove iframe because removal is started from the same thread, from method fired from iframe itself. Maybe it's wrong. Setting timeout creates another thread. And, as a result, removal becomes available.


Jan 22, 2010 at 12:23 PM // reply »
1 Comments

That's incredible! You just fixed my lib :-D
PS: Working ok with a 50ms delay


Jan 22, 2010 at 5:07 PM // reply »
11,246 Comments

@Bert,

Awesome!


Mar 27, 2010 at 6:47 PM // reply »
2 Comments

This works great! It also works with a 0ms delay for me.


Mar 28, 2010 at 5:50 PM // reply »
2 Comments

By the way, just found this while investigating other problems:
https://developer.mozilla.org/en/DOM/window.setTimeout#Minimum_delay_and_timeout_nesting

This explains why it is safe to use a small delay:
"In addition to 'clamping', the timeout can also fire later when the page (or the OS/browser itself) is busy with other tasks."


Apr 21, 2010 at 10:09 AM // reply »
11,246 Comments

@Ulrich,

Hmm, I wonder how they came up with the term, "clamping"? In any case, thanks for posting that - I had no idea.


Dec 12, 2010 at 7:22 PM // reply »
1 Comments

Thanks a bunch! I was struggling with this and it happened to be for precisely the same reason--and AJAX file upload script. I added a delay to my cleanup() and now all is good.



Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
May 23, 2013 at 6:06 PM
The Girl Who Broke My Heart, And Made Me A Better Person
Good day,ladies and gentle men, my name is Dr AMADI the great spell caster in Africa, i have help so many people for different kind of problems,who say there is no solution to problems on earth, that ... read »
May 23, 2013 at 4:26 PM
ColdFusion QueryAppend( qOne, qTwo )
@Heather, Glad people are still getting value out of this! ... read »
May 23, 2013 at 3:49 PM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@WebManWalking, I meant the code at the bottom (not the video). I did try to experiment with an intermediary variable, like: value = users.id[ i ]; arrayContains( userIDs, value ); ... but t ... read »
May 23, 2013 at 11:06 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@Ben, Are you talking about As Number: YES As String: YES As Java: YES? If so, that's with 3 different ways of referencing the constant 1, not users.id[1]. Query object references(*) are what seem ... read »
May 23, 2013 at 9:55 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@Dan, According to the CF Admin, I'm running Java "1.6.0_45". As far as the DB column, in the database it's an INT. I'll see if I can dig into what CF sees it as. @WebManWalking, But h ... read »
May 23, 2013 at 9:49 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@Ben, I think the problem is that we're used to loose typing in ColdFusion, like JavaScript. If a value is a number but it's needed in an expression to be a string, noooo problem. I've encountered ... read »
May 23, 2013 at 9:47 AM
ColdFusion QueryAppend( qOne, qTwo )
You rock! Thank you, thank you, thank you!!! ... read »
May 23, 2013 at 5:19 AM
Ask Ben: Print Part Of A Web Page With jQuery
How to print also the background color of table cells and table lines ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools