Javascript addEventListener onStateChange not working in IE(Javascript addEventListener onStateChange 在 IE 中不起作用)
问题描述
我有两个颜色框弹出框,每个框都显示一个 YouTube 视频.当他们完成播放时,我试图让他们自动关闭彩盒窗口.下面的代码在 Firefox 中完美运行,但在 IE 中我无法让 addEventListener
工作.我试过 attachEvent
没有成功.任何人都可以就如何解决这个问题提供任何建议吗?这看起来很简单,但我已经筋疲力尽地试图找到解决方案.
I have two colorbox popup boxes which show a YouTube video in each. When they're finished playing, I'm trying to have them automatically close the colorbox window. This code below works perfect in Firefox, but in IE I can't get addEventListener
to work. I've tried attachEvent
with no success. Can anybody offer any suggestions as to how to solve this? It seems simple but I'm exhausted trying to find a solution.
更新 1:
嗯,这是我当前的代码.它在 Firefox 中完美运行,但 IE 仅输出良好.IE8 调试器也不报任何错误...
Well, this is my current code. It works perfect in Firefox, but IE only outputs good. IE8 debugger doesn't report any errors either...
function onYouTubePlayerReady(playerId) {
if (playerId && playerId != 'undefined') {
if(playerId && playerId == 'ytvideo1'){
var ytswf = document.getElementById('ytplayer1');
alert('good');
} else if(playerId && playerId == 'ytvideo2'){
var ytswf = document.getElementById('ytplayer2');
} else {
}
setInterval('', 1000);
ytswf.addEventListener('onStateChange', 'onytplayerStateChange');
alert('great');
}
}
function onytplayerStateChange(newState) {
alert('amazing');
if(newState == 0){
$.fn.colorbox.close();
alert('perfect');
}
}
更新 3:解决方案
只需将 onComplete 放入我的颜色框中,然后将 swfobject 放入其中即可在 IE 中完美运行.
Simply put onComplete in my colorbox and put the swfobject in that and it worked perfectly in IE.
推荐答案
在 IE 中测试看起来像你正在使用的参考
from testing in IE it looks like the reference you are using
ytswf = document.getElementById('ytplayer1');
在加载实际 swf 对象之前分配,因此 IE 认为您指的是简单的 div 元素
is assigned before the actual swf object is loaded, so IE thinks you are referring to a simple div element
你需要运行这段代码
function onYouTubePlayerReady(playerId) {
ytswf = document.getElementById("ytplayer1");
ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
}
在你打电话后
swfobject.embedSWF("http://www.youtube.com/v/SPWU-EiulRY?
hl=en_US&hd=0&rel=0&fs=1&autoplay=1&enablejsapi=1&playerapiid=ytvideo1",
"popupVideoContainer1", "853", "505", "8", null, null, params, atts);
在你关闭 $(function()
并放置 var ytswf;
<script>
之后而不是进一步向下
and place var ytswf;
right after the <script>
instead of further down
这篇关于Javascript addEventListener onStateChange 在 IE 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Javascript addEventListener onStateChange 在 IE 中不起作用
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- Flexslider 箭头未正确显示 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 400或500级别的HTTP响应 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01