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 中不起作用
基础教程推荐
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01