I seem to be having a little problem with my JavaScript: it works as expected on JSFiddle, but not when opened from a local .html
file.
Here's the code as it is on my hard disk:
<html>
<head>
<script type='text/javascript'>
window.onPlayerLoad = function () {
alert("test");
};
</script>
</head>
<body>
<object bgcolor='#000000' data='http://www.twitch.tv/widgets/archive_embed_player.swf' height='378' id='clip_embed_player_flash' type='application/x-shockwave-flash' width='620'>
<param name='movie' value='http://www.twitch.tv/widgets/archive_embed_player.swf'>
<param name='allowScriptAccess' value='always'>
<param name='allowNetworking' value='all'>
<param name='allowFullScreen' value='true'>
<param name='flashvars' value='title=IEM%2BSingapore&channel=esltv_sc2&auto_play=false&start_volume=25&archive_id=484099469&initCallback=onPlayerLoad'>
</object>
</body>
</html>
And here it is on JSFiddle: http://jsfiddle.net/77Bpa/.
The purpose of this code is to load a Twitch player and call a function once it has finished loading. The function that should be called is window.onPlayerLoad
, and it is passed to the flash object through the initCallback
flashvar (see the Twitch Player API).
And so, on JSFiddle the alert pops up as expected, however when I open the file locally there is no such effect. Both Firefox and Internet Explorer say that window.onPlayerLoad
exists, but it is not getting called.
What might be the cause of this problem?
Thanks in advance.
As stated in my comment the issue is that the flash doesn't invoke callback because of some, unknown to me reason - related to the protocols used in request of the page that it is used on. Using http:// over file:// solves the issue. So simply uploading or using local host to request a page with the player works fine and fails when loading a html file into browser from local filesystem.