youtube js api,internet explorer(8 +,inc.10)" SCRIPT438:对象不支持属性或方法' playVideo' "

时间:2014-05-11 17:22:43

标签: javascript internet-explorer youtube-api youtube-javascript-api

div视频最初是隐藏的(使用display: none;),但iframe似乎加载得很好,按下按钮后我首先将display: none;更改为display: block;,然后执行玩家(这是yt玩家的实例)player.playVideo(),没什么不寻常的,真的。但它抛出了这个错误。

注销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,我该怎么办?

1 个答案:

答案 0 :(得分:1)

原因确实只是因为div最初是隐藏的,所有你需要做的就是以其他方式隐藏它,我在visibility: hidden;opacity: 0;上并没有取得多大成功,top: -alot;以及父母overflow: hidden;完成了这项工作。

Harry Roberts的这段代码也可以完成这项工作。

/**
 * 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;
}