Last active
January 3, 2016 19:29
-
-
Save djyde/8508659 to your computer and use it in GitHub Desktop.
Parse RSS only in Javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//It depends on Google Feed API | |
//Check <script type="text/javascript" src="https://www.google.com/jsapi"></script> is included in HTML | |
var ggrss = (function(){ | |
var cache = []; | |
return { | |
parse: function(url,num,callback){ | |
google.load("feeds","1"); | |
//I found that google.load() should not be called while your page is ready, or the page will be cleared | |
//So the correct way to load API is loading it before all the DOM loaded | |
function initialize() { | |
var feed = new google.feeds.Feed(url); | |
feed.setNumEntries(num); | |
feed.load(function(result) { | |
if (!result.error) { | |
for (var i = 0; i < result.feed.entries.length; i++) { | |
var entry = result.feed.entries[i]; | |
cache.push(entry) | |
} | |
callback(result.error,cache) | |
} | |
}); | |
} | |
google.setOnLoadCallback(initialize); | |
}, | |
} | |
}()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example