onReady事件在IE11上未触发 [英] onReady event not firing on IE11
问题描述
onReady事件未在IE11& Edge,但它在IE10,Firefox,Safari和Google Chrome上正常工作。
当加载页面时,我使用javascript api来静音视频。
这是我写的代码。 (注意,我使用的是Drupal)
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.
推荐答案
我做了一些研究,发现IFrame API有一个暂时的问题。
对于临时修复,您可以查看以下相关的堆栈溢出:
YouTube iframe播放器API - OnStateChange不触发和 Youtube Iframe API在Internet Explorer(11)中不起作用
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)
这篇关于onReady事件在IE11上未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!