The first line:
var newsfeed=new gfeedfetcher("ample", "ampleclass", "_new")
must be loaded synchronously on the page, meaning it can't be put inside a function and called on demand. However, the subsequent lines inside the initialization code can. What you can do then is simply call the last line inside the initialization code on demand, when you wish the contents of the feed to actually be shown:
Code:
<html>
<head>
<script type="text/javascript" src="http://www.google.com/jsapi">
</script>
<script type="text/javascript" src="gfeedfetcher.js">
/***********************************************
* gAjax RSS Feeds Displayer- (c) Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
</script>
<script type="text/javascript">
function loadfeeds()
{
var newsfeed=new gfeedfetcher("ample", "ampleclass", "_new")
newsfeed.addFeed("BBC", "http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml")
newsfeed.displayoptions("label datetime snippet") //show the specified additional fields
newsfeed.definetemplate("<div style ='width: 410px; height:120px; padding: 4px; border: 1px solid sienna; float:left;'>{title}<br /><div style= 'color:brown; font-size: 90%; float:left; padding-right: 4px;'>{label} </div><div style='color:gray; font-size: 90%; float:left;'> {date}</div><br />{description}</div>")
newsfeed.setentrycontainer("p") //Display each entry as a p
newsfeed.filterfeed(40, "date") //Show 40 entries, sort by date
}
</script>
</head>
<body>
<button type="button" onclick = "newsfeed.init()">Load feeds</button>
</body>
</html>
Bookmarks