Adding Event Handler
Related Specification |
Main Reason |
Applies to |
---|---|---|
addEventListener, HTMLMediaElement |
webOS TV v2.0 and earlier |
Backward Compatible Code
When adding an event handler, you MUST use the addEventListener() method to make the code works on all versions of webOS TV:
var vid = document.getElementById("myVideo"); vid.addEventListener("loadeddata", function (event) { log(JSON.stringify(event)); }); <!-- HTML Code --> ... <video id="myVideo"> <source src="./video/oceans-clip.mp4" type="video/mp4" /> </video>
Why Use This Code?
In webOS TV 1.x and 2.0, when the event of HTMLMediaElement occurs, only the event handler registered by the addEventListener() method can be called. As below, if you have added an event handler as a property type, it will not work correctly.
var vid = document.getElementById("myVideo"); vid.onloadeddata = function (event) { log(JSON.stringify(event)); }); <!-- HTML Code --> ... <video id="myVideo"> <source src="./video/oceans-clip.mp4" type="video/mp4" /> </video>