CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript frameworks (http://www.codingforums.com/forumdisplay.php?f=62)
-   -   Javascript .play() and .pause() HTML5 methods - IE8 (http://www.codingforums.com/showthread.php?t=288177)

obenns 02-23-2013 02:21 PM

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!

xelawho 02-23-2013 03:29 PM

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

obenns 02-23-2013 05:47 PM

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. :)

xelawho 02-23-2013 07:55 PM

just guessing really, but you might need to go one step further:

Code:

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

devnull69 02-23-2013 11:36 PM

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") {

xelawho 02-24-2013 12:19 AM

:thumbsup:

obenns 03-01-2013 12:32 PM

Sorry late reply. Thanks for this guys, much appreciated and should have known!


All times are GMT +1. The time now is 09:57 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.