DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Wesley Howard
Wesley Howard

Posted on

Having trouble with the YouTube API in IE 11

I'm hoping one of you might have an idea why my script isn't working in IE 11. Everything works in both Chrome and Firefox and partly works in IE. The issue though is that IE doesn't seem to like some of the functions I'm calling. IE Console - ("Object doesn't support this property or method 'pauseVideo'"). I cant escape the feeling that its some syntax error I'm not seeing.

Page displaying error - http://goforward.harpercollege.edu/dev-foundation/index-3.php

<script type="text/javascript" src="https://www.youtube.com/iframe_api"></script>

<script type="text/javascript">
window.onYouTubeIframeAPIReady = function() {
for (item in players_list) {
players[players_list[item]] = new YT.Player(players_list[item], {});
}
}
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var players = new Array();
var players_list = [
"popup-youtube-player-1",
"popup-youtube-player-2",
"popup-youtube-player-3",
"popup-youtube-player-4",
"popup-youtube-player-5",
"popup-youtube-player-6"
];

function pauseVideo() {
for (item in players_list) {
players[players_list[item]].pauseVideo();
}
}

function swapvid(id) {
pauseVideo();
$('.video-slider').css('display', 'none');
$('#' + id).closest('.video-slider').css('display', 'inline');  
}
</script>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Visualizing Promises and Async/Await 🀯

async await

☝️ Check out this all-time classic DEV post