onReady event not firing on IE11

烈酒焚心 提交于 2019-12-13 21:13:46

问题


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:


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)



来源:https://stackoverflow.com/questions/34596571/onready-event-not-firing-on-ie11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!