javascriptjqueryyoutubeswfobjectunobtrusive-javascript

IE8 wont run a specific JS function but will run another function with similar code


I have two functions that load in youtube videos with the swfobject.js and jquery to grab some json data from a youtube rss.

Both functions use very similar code to embed the videos with swfobject.js. I load up IE8 and when the dialog box pops up saying:

Line: 4
Char: 5 
Error: not implemented
Code: 0

If I hit YES, all the videos load. If I hit NO, only one of the 3 videos load. I just want to know why one of them will load but the others wont. Is there some obtrusive code that IE8 doesn't like here?

The code for the one that loads if I hit yes or no is here:

function getVideo(videoID, divName){//Gets yt video for yt category posts
    var videoURL = videoID;
    var divID = divName+'-video';
    var width = 392; //only change this number
    var height = Math.floor(width*9/16);

    var params = { allowScriptAccess: "always" };
    var atts = { 'class': 'hmt-ytvideo' };
    swfobject.embedSWF("http://www.youtube.com/v/"+videoURL+"?enablejsapi=1&playerapiid=ytplayer&version=3",
                       divID, width, height, "8", null, null, params, atts);
}

<script type="text/javascript">
    var youtubeID = '<?php echo $urlYoutube; //pass the php var to js var?>';
    var divID = '<?php echo $divName; //pass the php var to js var?>';
    addLoadEvent(getVideo(youtubeID, divID));//Onload function to output video
</script>

The code for the one that loads when I hit yes and doesn't load when I hit no is here:

function getFirstSideVideo(){
    //First sidebar video, represented by the url 'start-index' value
    $j.getJSON(rssFeedURL, function(data) {
        $j.each(data.feed.entry, function(i, item) {
            var updated = item.updated;
            var urlLink = item['link'][4]['href'];
            var width = 315; //only change this number
            var height = width*9/16;

            //SWF object params
            var videoURL = urlLink.split('/uploads/')[1];
            var params = { allowScriptAccess: "always" };
            var atts = { 'class': 'hmt-ytvideo' };
            var divID = 'first-sidebar-video';

            //Output video with swf object
            swfobject.embedSWF("http://www.youtube.com/v/"+videoURL+"?enablejsapi=1&playerapiid=ytplayer&version=3",
                               divID, width, height, "8", null, null, params, atts);
        });
    });
}

<script type="text/javascript">//Onloads the function to output the video
    addLoadEvent(getFirstSideVideo);
</script>

Solution

  • This error is happening because you aren't passing a function to the addLoadEvent method.

    addLoadEvent(getVideo(youtubeID, divID));

    This code executes getVideo(youtubeID, divID) then since nothing is returned from that function undefined is passed on to the addLoadEvent function.

    Which is just so happens that in IE 8 when you try to assign undefined to window.onload you now have that error you got. The window.onload is done internally by the addLoadEvent function.