IE11 JavaScript(错误:SCRIPT445)“对象不支持此操作" [英] IE11 JavaScript (Error: SCRIPT445) "Object doesn't support this action"

查看:38
本文介绍了IE11 JavaScript(错误:SCRIPT445)“对象不支持此操作"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I use a Javascript solution which loads the youtube player API asynchronously. The whole script is supposed to play the video when scrolled to its position. It works in all browsers and also in IE(11), but sometimes in IE I get an error in Developer Tools: SCRIPT445 (Object doesn't support this action).

Youtube 播放器仍然有效,但它似乎使其他脚本崩溃.我在网上和 Stackoverflow 上环顾四周.似乎还有其他人有类似的问题,但他们太具体了.也许有人可以帮我解决这个问题.这是导致问题的代码部分:

The Youtube Player still works but it seems to crash other scripts. I looked around in the web and also here on Stackoverflow. There seem to be others who have similar problems but they were too specific. Maybe someone could help me with this one. Here is the part of the code which makes the problem:

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);
});

推荐答案

IE 中存在竞争条件,它会在评估整个脚本之前触发脚本加载器回调.通过使用 setTimeout(initYT, 0),您将允许脚本在触发初始化函数之前完成评估.很高兴它奏效了!

There is a race condition in IE that is firing off your script loader callback before the entire script is evaluated. By using setTimeout(initYT, 0) you will allow the script to finish evaluating before firing your initialization function. Glad it worked!

这篇关于IE11 JavaScript(错误:SCRIPT445)“对象不支持此操作"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆