I have several JavaScript functions that behave as event listeners for a <object/> that fires custom events. The object in question is a YouTube player with support for the JavaScript API. The documentation provides sample code for adding an event listener:
function onYouTubePlayerReady(playerId) { ytplayer = document.getElementById("myytplayer"); ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
However, according to addEventListener examples I saw elsewhere do not suggest using quotation marks:
function onytplayerStateChange(newState) { alert("Player new state: " + newState); } function onYouTubePlayerReady(playerId) { ytplayer = document.getElementById("myytplayer");
So which method is right? The first appeared in all browsers, but lately I have noticed strange problems, and I am wondering if these problems are related to the way the addEventListener method is called.
source share