PDA

View Full Version : RSS to JavaScript



DimaUKR
01-13-2016, 02:36 PM
Hello,
How to add the date and a few words from articles to this javascript?
// <div id="feeddiv"></div>


<script type="text/javascript" src="http://www.google.com/jsapi">
</script>

<script type="text/javascript">
google.load("feeds", "1") //Load Google Ajax Feed API (version 1)
</script>


<div id="feed"></div>
<script type="text/javascript">
var feedcontainer=document.getElementById("feed")
var feedurl="http://www.npr.org/rss/rss.php?id=1006"
var feedlimit=10
var rssoutput="<ul>"

function rssfeedsetup(){
var feedpointer=new google.feeds.Feed(feedurl)
feedpointer.setNumEntries(feedlimit)
feedpointer.load(displayfeed)
}

function displayfeed(result){
if (!result.error){
var thefeeds=result.feed.entries
for (var i=0; i<thefeeds.length; i++)
rssoutput+="<li><a href='" + thefeeds[i].link + "'>" + thefeeds[i].title + "</a></li>"
rssoutput+="</ul>"
feedcontainer.innerHTML=rssoutput
}
else
alert("Error fetching feeds!")
}

window.onload=function(){
rssfeedsetup()
}

</script> //

ddadmin
01-13-2016, 11:26 PM
Take a look at the following page: http://www.javascriptkit.com/dhtmltutors/googleajaxfeed2.shtml You can access thefeeds[i].content or thefeeds[i].contentSnippet to display a portion of each entry's description/ content.

DimaUKR
01-20-2016, 12:33 PM
Thank you! That helps! But one more question...How can I take certain tags out of this NPR feed? For example, I want just news with tags "space", or "science".