I have a WMP player object and I'm trying to add an event listener to intercept ScriptCommands that are sent to the player. Instead of being attached to the WMP object, my callback is being called right away, and then the ScriptCommands aren't being intercepted.
我有一个WMP播放器对象,我正在尝试添加一个事件监听器来拦截发送给播放器的ScriptCommands。而不是附加到WMP对象,我的回调被立即调用,然后ScriptCommands没有被截获。
function init() {
var WMPlayer = document.getElementById("WMPlayer");
WMPlayer.addEventListener("ScriptCommand", MyScriptCommand(), false);
alert('init');
}
function MyScriptCommand() {
alert('script');
}
When I run this, I get the script alert before the init alert.... Does anyone know why this might be happening?
当我运行这个时,我会在init警报之前得到脚本警报....有谁知道为什么会发生这种情况?
1 个解决方案
#1
WMPlayer.addEventListener("ScriptCommand", MyScriptCommand(), false);
needs to be
需要是
WMPlayer.addEventListener("ScriptCommand", MyScriptCommand, false);
without the parantheses. With the paranthese, you are calling the function and passing its return value as the listener, rather than the reference to the actual function.
没有parantheses。使用paranthese,您将调用该函数并将其返回值作为侦听器传递,而不是对实际函数的引用。
#1
WMPlayer.addEventListener("ScriptCommand", MyScriptCommand(), false);
needs to be
需要是
WMPlayer.addEventListener("ScriptCommand", MyScriptCommand, false);
without the parantheses. With the paranthese, you are calling the function and passing its return value as the listener, rather than the reference to the actual function.
没有parantheses。使用paranthese,您将调用该函数并将其返回值作为侦听器传递,而不是对实际函数的引用。