Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-23-2013, 02:21 PM   PM User | #1
obenns
New Coder

 
Join Date: Nov 2011
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
obenns is an unknown quantity at this point
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!
obenns is offline   Reply With Quote
Old 02-23-2013, 03:29 PM   PM User | #2
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
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
xelawho is offline   Reply With Quote
Old 02-23-2013, 05:47 PM   PM User | #3
obenns
New Coder

 
Join Date: Nov 2011
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
obenns is an unknown quantity at this point
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.
obenns is offline   Reply With Quote
Old 02-23-2013, 07:55 PM   PM User | #4
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
just guessing really, but you might need to go one step further:

Code:
if (typeof(document.getElementById('js-video').pause())!="function") {
xelawho is offline   Reply With Quote
Old 02-23-2013, 11:36 PM   PM User | #5
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,261
Thanks: 10
Thanked 533 Times in 527 Posts
devnull69 will become famous soon enough
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") {
devnull69 is offline   Reply With Quote
Old 02-24-2013, 12:19 AM   PM User | #6
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
xelawho is offline   Reply With Quote
Old 03-01-2013, 12:32 PM   PM User | #7
obenns
New Coder

 
Join Date: Nov 2011
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
obenns is an unknown quantity at this point
Sorry late reply. Thanks for this guys, much appreciated and should have known!
obenns is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:00 PM.


Advertisement
Log in to turn off these ads.