Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Internet Explorer Javascript .play() and .pause() HTML5 methods - IE8

    Hi there.

    Well aware IE8 won't support my html5 audio or video, thats no problem what so ever. However I have some javascript that plays these at certain points, some on hover, some on click, doc load etc etc.

    The problem is IE8 doesn't recognise it, and therefore doesn't execute anymore of my javascript, even other functions.

    e.g.

    $(document).ready(function() {

    $('#music').pause(); // Not supported in IE8

    function() { // Supported in IE8 yet not running. due to the above.
    Whatever code
    }
    }

    How can I make IE8 ignore these methods?

    Thanks lifesavers!

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    3,020
    Thanks
    56
    Thanked 566 Times in 563 Posts
    I'm not sure about the specifics of the audio player, but generally you can test for the existence of a function before calling it, and wrap the necessary code in that code block

    Code:
    if($('#music').pause()){
    // put all your non-IE stuff here 
    }
    // rest of code goes outside of "if" statement
    there are other ways of browser sniffing, of course, but they can be unreliable - to me it seems logical that if you are unsure if a function is going to run, to simply test if that function is recognised first

  • #3
    New Coder
    Join Date
    Nov 2011
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Internet Explorer

    Hey thanks for your quick reply. There is no player as such, it's in the background (invisible if you will.)

    I've stripped out the jQuery back to Vanilla and got this but it's still not liking it, any suggestions?

    if (document.getElementById('js-video').pause()) {
    document.getElementById('js-video').pause();
    alert('1');
    }
    // Check if support
    if (document.getElementById('js-audio').pause()) {
    document.getElementById('js-audio').pause();
    alert('2');
    }

    Chrome pauses fine, except alerts don't appear. IE8 still won't load rest of JS.

    Thanks.

  • #4
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    3,020
    Thanks
    56
    Thanked 566 Times in 563 Posts
    just guessing really, but you might need to go one step further:

    Code:
    if (typeof(document.getElementById('js-video').pause())!="function") {

  • #5
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    One important mistake: You should check the method and not the result of the method execution. Bottom line: You have to omit the parentheses.

    Code:
    if (typeof document.getElementById('js-video').pause !== "function") {

  • #6
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    3,020
    Thanks
    56
    Thanked 566 Times in 563 Posts

  • #7
    New Coder
    Join Date
    Nov 2011
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry late reply. Thanks for this guys, much appreciated and should have known!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •