I have tried in JSFiddle, on my local server, and on a production server, and I cannot figure out what is wrong with my event handler. It never fires. Also, when I run in Google Chrome I get no errors, when I run in Safari, I get:
Blocked a frame with origin "http://www.youtube.com" from accessing a frame with origin "http://jsfiddle.net". Protocols, domains, and ports must match.
What am I missing?
Code:
<script src="http://www.youtube.com/player_api"></script>
<iframe
id="player"
width="426"
height="240"
src="http://www.youtube.com/embed/21eGxOKUxeM?enablejsapi=1&origin=*"
frameborder="0"
allowfullscreen></iframe>
<script>
function player_state_changed(state) {
alert('state changed');
}
document.getElementById('player').addEventListener(
'onStateChange', player_state_changed
);
</script>