youtube js API,Internet Explorer(8+,公司10)"SCRIPT438:对象不支持属性或方法"playVideo" [英] youtube js api, internet explorer(8+, inc. 10) "SCRIPT438: Object doesn't support property or method 'playVideo' "
问题描述
div最初是隐藏的(带有display: none;
),但是iframe似乎加载得很好,按下按钮后,我首先将display: none;
更改为display: block;
,然后执行player(这是实例) (yt player)player.playVideo()
,真的没什么不寻常的.但这会引发此错误.
div with the video is initially hidden(with display: none;
), but iframe seems to be loaded just fine, on press of a button I first change display: none;
to display: block;
, then do player(which is the instance of yt player) player.playVideo()
, nothing unusual, really. But it throws this error.
注销player.playVideo
确实会返回undefined
.
记录player
,返回此
{
"b":{
"b":{
"width":1259,
"height":709,
"videoId":"videaidhere",
"playerVars":{
"autoplay":0,
"controls":0,
"showinfo":0,
"rel":0,
"modestbranding":1,
"html5":0,
"wmode":"transparent"
}
},
"defaults":{
"host":"http://www.youtube.com",
"title":"video player",
"videoId":"",
"width":640,
"height":360
},
"a":false
},
"a":{
"closure_uid_78774223":2
},
"o":{
},
"closure_uid_78774223":1,
"s":1,
"d":130,
"u":false,
"t":[
{
"event":"command",
"func":"addEventListener",
"args":[
"onReady"
]
},
{
"event":"command",
"func":"addEventListener",
"args":[
"onStateChange"
]
}
],
"g":{
"a":[
null,
"onReady",
null,
null,
"onStateChange",
null,
null
],
"b":{
"onReady":[
1
],
"onStateChange":[
4
]
},
"G":7
},
"h":"player",
"D":{
"onReady":true,
"onStateChange":true
},
"k":{
},
"i":{
}
}
它可用于除IE之外的所有浏览器,我该怎么办?
It works on every browser but IEs, what should I do?
推荐答案
原因确实是因为div最初是隐藏的,您需要做的只是以其他方式隐藏它,我并没有取得太大的成功visibility: hidden;
或opacity: 0;
,top: -alot;
加上父级为overflow: hidden;
即可完成工作.
The reason is indeed simply because the div is initially hidden, all you need to do is to hide it some other way, I didn't really have much success with visibility: hidden;
or opacity: 0;
, top: -alot;
along with parent being overflow: hidden;
did the job.
哈里·罗伯茨(Harry Roberts)编写的这段代码也可以完成这项工作.
This piece of code from Harry Roberts could probably do the job as well.
/**
* Hide content off-screen without resorting to `display:none;`, also provide
* breakpoint specific hidden elements.
*/
@mixin accessibility{
border:0!important;
clip:rect(0 0 0 0)!important;
height:1px!important;
margin:-1px!important;
overflow:hidden!important;
padding:0!important;
position: absolute!important;
width:1px!important;
}
这篇关于youtube js API,Internet Explorer(8+,公司10)"SCRIPT438:对象不支持属性或方法"playVideo"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!