一些jQuery脚本不能在IE和Opera上运行

时间:2013-04-10 18:21:10

标签: javascript jquery wordpress internet-explorer opera

我正在使用一些jQuery脚本从Flickr和YouTube获取JSON提要,并在我的WordPress网站上生成HTML 对于Flickr我使用它在除Opera之外的所有浏览器上都能正常工作:

<!-- Script to grab photos from Flickr feed -->
<script type="text/javascript">
// Set variables needed for query
var URL = "http://api.flickr.com/services/feeds/photos_public.gne";
var ID = "<?php echo get_option('of_flickrid') ?>";
var jsonFormat = "&lang=en-us&format=json&jsoncallback=?";

var ajaxURL = URL + "?id=" + ID + jsonFormat;
// Get the last photos of the flickr account, parse it into HTML code
$.getJSON(ajaxURL, function(data){
     var htmlString = "<h1><?php echo get_option('of_photostext') ?></h1>";

    // Now start cycling through our array of Flickr photo details
    $.each(data.items, function(i,item){

        // I only want the ickle square thumbnails
     var sourceSquare = (item.media.m).replace("_m.jpg", "_s.jpg");

        // Here's where we piece together the HTML
        htmlString += '<a href="' + item.link + '" target="_blank">';
        htmlString += '<img title="' + item.title + '" src="' + sourceSquare;
        htmlString += '" alt="'; htmlString += item.title + '" class="rounded"/>';
        htmlString += '</a>';
        if(i === 11){
            return false;
        }
    });

    // Pop our HTML in the #images DIV
    $('#photos').html(htmlString);

}); // End getJSOON
</script>
<!-- End of Script to grab photos from Flickr feed -->

对于YouTube,它适用于所有期望IE的浏览器:

<!-- Script to grab videos from YouTube feed -->
<script type="text/javascript">
// Set variables needed for query
var URL = "https://gdata.youtube.com/feeds/api/users/";
var UserName = "<?php echo get_option('of_youtubeid') ?>";
var jsonFormat = "/uploads?v=2&alt=jsonc&max-results=2";
// Construct the JSON feed of the YouTube user's channel
var ajaxURL = URL + UserName + jsonFormat;
// Get the last videos of the YouTube account, parse it into HTML code
$.getJSON(ajaxURL, function(data){
     var htmlString = "<h1><?php echo get_option('of_videostext') ?></h1>";

    $.each(data.data.items, function(i,item){       
        // Here's where we piece together the HTML
        htmlString += '<iframe class="videos" type="text/html" width="640" height="390" src="http://www.youtube.com/embed/';
        htmlString += item.id;
        htmlString += '?autoplay=0" frameborder="0"></iframe>';
    });

    // Pop our HTML in the #videos DIV
    $('#videos').html(htmlString);
});
</script>
<!-- End of Script to grab videos from YouTube feed -->

我将这些脚本作为普通JavaScript插入header.php中。可能出了什么问题?这与我在WordPress中插入脚本的方式有关吗?有线索吗?

更新 我添加了一个jsoncallback =?对于YouTube JSON提要,这使它在IE上运行但在Opera中消失了,这让我猜到Opera错误与Opera上的回调函数有关吗?

0 个答案:

没有答案