0

I wonder if anyone can help with something. I work on a website which contains a form. When the form is submitted, we display an overlay which contains an animated gif - a 'please wait' type thing.

When we first developed the code we had terrible problems with the animated gif in that it would hang on the first frame when the form was submitted. We found that decent browsers :) were all consistent in that we had to display the overlay, then wait a short period of time before submitting the form. We also found that IE required the opposite - we have to submit the form, then display the overlay. To add to this, we found that different versions of IE behaved differently in this respect (no surprise there!)

We eventually came up with the following:

<!DOCTYPE html>
<!--[if lt IE 7 ]> <html lang="en" class="ie6"> <![endif]-->
<!--[if IE 7 ]>    <html lang="en" class="ie7"> <![endif]-->
<!--[if IE 8 ]>    <html lang="en" class="ie8"> <![endif]-->
<!--[if IE 9 ]>    <html lang="en" class="ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class=""> <!--<![endif]-->
    <head>
        ....

and

  /* we need to do a minor hack here to ensure the animated gif continues to animate
   * for IE we need to submit the form BEFORE we load the overlay
   * for other browsers we need to submit the form shortly AFTER loading the overlay
   * Not ideal, but we'll use the css class applied to the html element to test
   * Perhaps in the future a more elegant solution might be to use something like Modernizr
   *
   * Note particular case for ie7, which requires a further step.
   * By copying the html of the overlay and reapplying it, the browser is forced to re-render the page
   */
  if (htmlElement.hasClass("ie6") || htmlElement.hasClass("ie8") || htmlElement.hasClass("ie9")) {
        $("form")[0].submit();
        $('#waitOverlay').overlay().load();
  } else if (htmlElement.hasClass("ie7")) {
        $("form")[0].submit();
        var waitOverlayHtml = $("#waitOverlay").html();
        $("#waitOverlay").html(waitOverlayHtml + "");
        $('#waitOverlay').overlay().load();
  } else {
        $('#waitOverlay').overlay().load();
        setTimeout(function() {
              $("form")[0].submit();
        }, 250);
  }

This has been working well since being implemented. However, it relies on our use of conditional comments in the markup ... and good old IE10 has dropped support for conditional comments!

When IE10 runs this code, it falls into the else block as if it were a 'decent' browser. Whilst the site and page functionality still works - the overlay is displayed and the form is submitted - the animated gif does not animate! And our marketing department are very unhappy about this!! :(

I've not tested, but I suspect to get IE10 to work properly it will need to run the first if branch; the same code that IE6, 8 and 9 need to run.

I've looked briefly at trying to apply an ie10 class to the html element, but everything I've read (and the comment which we left in the original code 'Perhaps in the future a more elegant solution might be to use something like Modernizr') suggests this is not the way to do it.

So, assuming we used some feature detection library such as Modernizr, we would change our javascript as follows:

  if ( browser has feature that makes IE6, IE8, IE9 and IE10 behave the way they do ) {
        $("form")[0].submit();
        $('#waitOverlay').overlay().load();
  } else if ( browser has feature that makes IE7 behave the way it does ) {
        $("form")[0].submit();
        var waitOverlayHtml = $("#waitOverlay").html();
        $("#waitOverlay").html(waitOverlayHtml + "");
        $('#waitOverlay').overlay().load();
  } else if ( browser has feature that makes standards compliant browsers behave the way they do ) {
        $('#waitOverlay').overlay().load();
        setTimeout(function() {
              $("form")[0].submit();
        }, 250);
  }

So, my question is, does anyone know the features I should be looking to detect in the above code?

Sam Hanley
  • 4,707
  • 7
  • 35
  • 63
Nathan Russell
  • 3,428
  • 5
  • 30
  • 51
  • Slightly harsh down vote alex23 isn't this? My question is not should I be using Modernizr, but what specific polyfills or feature detections should I be using for my specific circumstance – Nathan Russell May 01 '13 at 10:09
  • have you considered dropping support for IE6 and IE7? It would simplify things a lot. (and it's not as if you're actually getting IE6/7 visitors in any significant numbers, right?) – Spudley May 01 '13 at 11:20
  • @Spudley, yes, dropping IE6 & 7 support might be an option. Then I guess the question becomes what feature detection do I need to detect between IE and standards compliant browsers? – Nathan Russell May 01 '13 at 11:25
  • Also, to change the tack a bit: IE10 is a decent, standards-compliant browser. It's unusual to need to use the sort of techniques you've described for IE10. It's a shame you haven't shown us the actual thing that isn't working with it, because I suspect if you'd asked for it you'd have got help with making your code work cross platform without needing all that browser-specific code at all, at least for modern browsers. Can you provide a demo of the problem (or maybe ask a separate question) – Spudley May 01 '13 at 11:25
  • 1
    possibly [this question](http://stackoverflow.com/questions/780560/animated-gif-in-ie-stopping) might be related to the specific thing you'r trying to hack? maybe some of the answers there will help? – Spudley May 01 '13 at 11:27

0 Answers0