gpt4 book ai didi

javascript - IE11 JavaScript(错误 : SCRIPT445) "Object doesn' t support this action"

转载 作者:数据小太阳 更新时间:2023-10-29 04:11:27 24 4
gpt4 key购买 nike

我使用异步加载 youtube 播放器 API 的 Javascript 解决方案。整个脚本应该在滚动到其位置时播放视频。它适用于所有浏览器以及 IE(11),但有时在 IE 中我在开发人员工具中收到错误:SCRIPT445(对象不支持此操作)

Youtube 播放器仍然有效,但它似乎会使其他脚本崩溃。我在网上四处查看,也在 Stackoverflow 上查看。似乎还有其他人有类似的问题,但他们太具体了。也许有人可以帮我解决这个问题。这是造成问题的代码部分:

var yt_int, yt_players={},
initYT = function() {
$(".ytplayer").each(function() {
yt_players[this.id] = new YT.Player(this.id); <-- Error line
});
};

$.getScript("//www.youtube.com/player_api", function() {
yt_int = setInterval(function(){
if(typeof YT === "object"){
initYT();
clearInterval(yt_int);
}
},500);
});

最佳答案

对象不支持此操作是错误是在 IE11 中使用 window.dispatchEvent(new Event('resize'));我们需要处理 ie11 的条件。

 if (navigator.userAgent.indexOf('MSIE') !== -1 || navigator.appVersion.indexOf('Trident/') > 0) {
var evt = document.createEvent('UIEvents');
evt.initUIEvent('resize', true, false, window, 0);
window.dispatchEvent(evt);
} else {
window.dispatchEvent(new Event('resize'));
}

关于javascript - IE11 JavaScript(错误 : SCRIPT445) "Object doesn' t support this action",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31765353/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com