Search code examples
jqueryflashinternet-explorervideoflowplayer

get(0).play() -- Internet Explorer error


I have this to show a video modal which works well in all browsers except IE (specifically IE8):

//Video
$("#siteNav li.nav5 a").click(function(){
   $("#video").fadeIn();
   $(".commercial").get(0).play();
   return false;
});

$("#video").click(function(event){
   $(this).fadeOut();
   $(".commercial").get(0).pause();
   return false;
});

If I click this, IE says "Error on page" and reloads.

If I comment out the line $(".commercial").get(0).play/pause(); the error doesn't show.

Any ideas how I can write this with an IE-friendly alternative?

I should also mention I use HTML5 video for compatible browsers, and Flowplayer/Flash for IE.


Solution

  • If you are using flowplayer for IE browser then try below code.

    //Video
    $("#siteNav li.nav5 a").click(function(){
       $("#video").fadeIn();
       if($.browser.msie)
         $f($(".commercial").get(0)).play();
       else
         $(".commercial").get(0).play(); 
       return false;
    });
    
    $("#video").click(function(event){
       $(this).fadeOut();
       if($.browser.msie)
         $f($(".commercial").get(0)).pause();
       else
         $(".commercial").get(0).pause(); 
       return false;
    });