开发者

How to get <img> tag from a blogger json-in-script file with javascript?

开发者 https://www.devze.com 2023-03-26 23:15 出处:网络
Im working with Blogger, and I need to get the last images from latest posts using the JSON feed API, in which you set the FEED mode to \"json-in-script\".

Im working with Blogger, and I need to get the last images from latest posts using the JSON feed API, in which you set the FEED mode to "json-in-script".

Google Description of JSON BLOGGER API

I was studying the code, but I开发者_StackOverflow could not find any way to get what I want. I could extract media$thumbnails, but I need to resize the images, so I need the original size.

Does anybody knows?

Extra: How could I make jQuery works in Blogger?


Here is a jQuery snippet that should help you. It gets your feed, loops over the posts and grabs all the image references. Once you have the image references in an array you should be able to process them as you want. Don't forget to update the "feedURL" with your correct domain before using the script.

<script type="text/javascript">
$(document).ready(function() {
    var imgArray = new Array(); // Holds array of images
    var feedURL = 'http://<yourdomain.com>/feeds/posts/default?alt=json-in-script&callback=?';

    // Make ajax call to blogger
    $.ajax({
        url: feedURL,
        dataType: 'jsonp',
        success: function(data) {
            // Loop over each post
            $.each(data.feed.entry, function(idx, ele) {
                // Get image references
                var matches = new Array();
                if( (matches = ele.content.$t.match(/https?:\/\/.+?\.(jpg|gif|png)/gi)) != null )
                {
                    $.merge(imgArray, matches);
                }
            });
        }       
    });

    // do something with imgArray here
    // ...
});
</script>
0

精彩评论

暂无评论...
验证码 换一张
取 消