PDA

View Full Version : gfeedfetcher inside a function not working in Firefos 19, Ubuntu



Charly
03-07-2013, 03:23 PM
1) Script Title: gfeedfetcher.js

2) Script URL (on DD): http://elot.ca/classify/newsfeed.php

3) Describe problem: I have wrapped the script contents inside a function, it is activated with a button, It works in Google Chrome but not in Firefox 19.0
<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
newsfeed.init() //Always call this last
}
</script>
</head>
<body>
<button type="button" onclick = loadfeeds()>Load feeds</button>
</body>
</html>

ddadmin
03-07-2013, 05:48 PM
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:


<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>

Charly
03-07-2013, 06:56 PM
Thanks for that, you have saved me some head scratching.:)