IE8不会运行特定的JS函数,但会运行具有类似代码的另一个函数

时间:2012-08-11 01:42:17

标签: javascript jquery youtube swfobject unobtrusive-javascript

我有两个函数可以在youtube视频中加载swfobject.js和jquery来从youtube rss中获取一些json数据。

两个函数都使用非常相似的代码将视频嵌入到swfobject.js中。我加载了IE8,弹出对话框时说:

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

如果我点击“是”,则会加载所有视频。如果我点击“否”,则只会加载3个视频中的一个。我只是想知道为什么其中一个会加载但其他人不会。是否有一些IE8不喜欢的突兀代码?

如果我点击是或否,加载的代码就在这里:

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>

当我点击“是”时加载的代码以及当我单击“否”时不加载的代码在此处:

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>

1 个答案:

答案 0 :(得分:1)

发生此错误是因为您没有将函数传递给addLoadEvent方法。

addLoadEvent(getVideo(youtubeID, divID));

此代码执行getVideo(youtubeID, divID),因为该函数不会返回任何内容undefined传递给addLoadEvent函数。

当您尝试将undefined分配给window.onload时,在IE 8中发生了这种情况,您现在遇到了错误。 window.onload由addLoadEvent函数在内部完成。

相关问题