Skip to content Skip to sidebar Skip to footer

How Do I Add An Event Listener?

Im using swfobject to embed the vimeo video, it's pretty simple, var vimPlayer; function vimeo_player_loaded(id){ vimPlayer = document.getElementById(id);

Solution 1:

$('video').bind('play', function (e) {
    // do something
});

try using this...

http://www.w3.org/2010/05/video/mediaevents.html

Solution 2:

If using Flash Embeds, where play() is prefixed to api_play(), the need to prefix also includes addEventListener():

vimPlayer.api_addEventListener('play', function () {
    alert('Playing');
});

This is demonstrated under Flash Embed Code:

To add a listener for the finish event:

document.getElementById('vimeo_player').api_addEventListener('finish', function(event) {
    // do stuff here
});

Solution 3:

Adding event listener takes three params, here's an example:

functiondoSomething() {
   alert('Image clicked');
}

var myButton = document.getElementById('my_button_id');

myButton.addEventListener('click', doSomething, false);

Solution 4:

I was stacking at exactly the same problem. As long as I tried countless times,

functionvimeo_player_loaded(id){        
    vimPlayer = document.getElementById(id);           
    vimPlayer.api_addEventListener('play', 'vimeo_play');
    vimPlayer.api_play();  
}
functionvimeo_play(){
    console.log("play");
}

This should work fine if the player_id and id in HTML are same. English is not my first language. Sorry if it's difficult to understand.

Post a Comment for "How Do I Add An Event Listener?"