onReady event not firing on IE11

2019-09-16 18:04发布

onReady event are not being fired on IE11 & Edge, but it's working fine on IE10, Firefox, Safari and Google Chrome. I'm using the javascript api to mute a video when the page is loaded. This is the code i wrote. (Note. I'm using Drupal)

(function ($) {
function onPlayerReady(event) {
    event.target.mute();
}

function muteVideos(video_ids) {

    for (var iframe_id in video_ids) {
        var player = new YT.Player(iframe_id, {
            videoId: iframe_id,
            playerVars:
            {
                "enablejsapi":1,
                "origin":document.domain,
                "rel":0
            },
            events: {
                "onReady": onPlayerReady
            }
        });
    }

}
function loadPlayer(video_ids) {

    if (typeof (YT) == 'undefined' || typeof (YT.Player) == 'undefined') {

        var tag = document.createElement('script');
        tag.src = "https://www.youtube.com/iframe_api";
        var firstScriptTag = document.getElementsByTagName('script')[0];
        firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

        window.onYouTubePlayerAPIReady = function () {
            muteVideos(video_ids);
        };
    } else {

        muteVideos(video_ids);
    }
}
Drupal.behaviors.eweev_media_youtube_video = {
    attach: function (context, settings) {
        // Array containing iframe ids of the youtube videos that should be
        //  muted provided using drupal_add_js 

        var video_ids = Drupal.settings.eweev_media_youtube_video;

        loadPlayer(video_ids);
    }
};

})(jQuery);

I wanna know if i'm missing something.

1条回答
Fickle 薄情
2楼-- · 2019-09-16 18:38

I did some research and found out that there is a temporary issue with the IFrame API. For temporary fix, you may view the related Stack overflow below: YouTube iframe player API - OnStateChange not firing and Youtube Iframe API not working in Internet Explorer (11)

查看更多
登录 后发表回答