Hi,
I've just been working on a News Ticker (to go on a site) using the BBC's XML feed.
Now, the script was a piece of cake to write. However, getting the news to actually show now is prooving to be more of a PITA :/
The outputted code looks like;
<html>
<head>
<title></title>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1" />
</head>
<body>
<div class="ticki"><a id="tickerAnchor" href="#" target="_top" class="tickl"></a></div>
<script language="JavaScript" type="text/javascript">
<!--
// Ticker startup
function startTicker()
{
// Define run time values
theCurrentStory = -1;
theCurrentLength = 0;
// Locate base objects
if (document.getElementById) {
theAnchorObject = document.getElementById("tickerAnchor");
runTheTicker();
}
else {
document.write("<style>.ticki{display:none;}.ticko{border:0px; padding:0px;}</style>");
return true;
}
}
// Ticker main run loop
function runTheTicker()
{
var myTimeout;
// Go for the next story data block
if(theCurrentLength == 0)
{
theCurrentStory++;
theCurrentStory = theCurrentStory % theItemCount;
theStorySummary = theSummaries[theCurrentStory].replace(/"/g,'"');
theTargetLink = theSiteLinks[theCurrentStory];
theAnchorObject.href = theTargetLink;
thePrefix = "<span class="tickls">" + theLeadString + "</span>";
}
// Stuff the current ticker text into the anchor
theAnchorObject.innerHTML = thePrefix +
theStorySummary.substring(0,theCurrentLength) + whatWidget();
// Modify the length for the substring and define the timer
if(theCurrentLength != theStorySummary.length)
{
theCurrentLength++;
myTimeout = theCharacterTimeout;
}
else
{
theCurrentLength = 0;
myTimeout = theStoryTimeout;
}
// Call up the next cycle of the ticker
setTimeout("runTheTicker()", myTimeout);
}
// Widget generator
function whatWidget()
{
if(theCurrentLength == theStorySummary.length)
{
return theWidgetNone;
}
if((theCurrentLength % 2) == 1)
{
return theWidgetOne;
}
else
{
return theWidgetTwo;
}
}
// -->
</script>
<script language="JavaScript" type="text/javascript">
<!--
var theCharacterTimeout = 50;
var theStoryTimeout = 5000;
var theWidgetOne = "_";
var theWidgetTwo = "-";
var theWidgetNone = "";
var theLeadString = "LATEST: ";
var theSummaries = new Array();
var theSiteLinks = new Array();
var theItemCount = 10;
theSummaries[0] = "Three killed as storms batter UK";
theSiteLinks[0] = "http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/uk/4164613.stm";
theSummaries[1] = "Blair to face MPs amid feud talk";
theSiteLinks[1] = "http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/uk_politics/4166625.stm";
theSummaries[2] = "Alarming ignorance of cancer risk";
theSiteLinks[2] = "http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/health/4164131.stm";
theSummaries[3] = "Boscastle awaits flooding report";
theSiteLinks[3] = "http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/uk/4166895.stm";
theSummaries[4] = "'Errors' doomed first Dome sale";
theSiteLinks[4] = "http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/uk_politics/4165767.stm";
theSummaries[5] = "Police launch Class A drugs blitz";
theSiteLinks[5] = "http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/uk/4166925.stm";
theSummaries[6] = "Businessman takes top MI6 job";
theSiteLinks[6] = "http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/uk/4166941.stm";
theSummaries[7] = "'vCJD timebomb' fears discounted";
theSiteLinks[7] = "http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/health/4162749.stm";
theSummaries[8] = "Greer attacks 'bully' Big Brother";
theSiteLinks[8] = "http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/entertainment/tv_and_radio/4165101.stm";
theSummaries[9] = "Football: Morientes close to move";
theSiteLinks[9] = "http://news.bbc.co.uk/go/click/rss/0.91/public/-/sport1/hi/football/teams/l/liverpool/4127559.stm";
theSummaries[10] = "Tennis: Henman winning start";
theSiteLinks[10] = "http://news.bbc.co.uk/go/click/rss/0.91/public/-/sport1/hi/tennis/4164273.stm";
startTicker();
//-->
</script>
</body>
</html>
Can anyone see any stupid mistakes?
Cheers
Andy (mod)
andy@ultranerds.co.uk
IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
I've just been working on a News Ticker (to go on a site) using the BBC's XML feed.
Now, the script was a piece of cake to write. However, getting the news to actually show now is prooving to be more of a PITA :/
The outputted code looks like;
Code:
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html>
<head>
<title></title>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1" />
</head>
<body>
<div class="ticki"><a id="tickerAnchor" href="#" target="_top" class="tickl"></a></div>
<script language="JavaScript" type="text/javascript">
<!--
// Ticker startup
function startTicker()
{
// Define run time values
theCurrentStory = -1;
theCurrentLength = 0;
// Locate base objects
if (document.getElementById) {
theAnchorObject = document.getElementById("tickerAnchor");
runTheTicker();
}
else {
document.write("<style>.ticki{display:none;}.ticko{border:0px; padding:0px;}</style>");
return true;
}
}
// Ticker main run loop
function runTheTicker()
{
var myTimeout;
// Go for the next story data block
if(theCurrentLength == 0)
{
theCurrentStory++;
theCurrentStory = theCurrentStory % theItemCount;
theStorySummary = theSummaries[theCurrentStory].replace(/"/g,'"');
theTargetLink = theSiteLinks[theCurrentStory];
theAnchorObject.href = theTargetLink;
thePrefix = "<span class="tickls">" + theLeadString + "</span>";
}
// Stuff the current ticker text into the anchor
theAnchorObject.innerHTML = thePrefix +
theStorySummary.substring(0,theCurrentLength) + whatWidget();
// Modify the length for the substring and define the timer
if(theCurrentLength != theStorySummary.length)
{
theCurrentLength++;
myTimeout = theCharacterTimeout;
}
else
{
theCurrentLength = 0;
myTimeout = theStoryTimeout;
}
// Call up the next cycle of the ticker
setTimeout("runTheTicker()", myTimeout);
}
// Widget generator
function whatWidget()
{
if(theCurrentLength == theStorySummary.length)
{
return theWidgetNone;
}
if((theCurrentLength % 2) == 1)
{
return theWidgetOne;
}
else
{
return theWidgetTwo;
}
}
// -->
</script>
<script language="JavaScript" type="text/javascript">
<!--
var theCharacterTimeout = 50;
var theStoryTimeout = 5000;
var theWidgetOne = "_";
var theWidgetTwo = "-";
var theWidgetNone = "";
var theLeadString = "LATEST: ";
var theSummaries = new Array();
var theSiteLinks = new Array();
var theItemCount = 10;
theSummaries[0] = "Three killed as storms batter UK";
theSiteLinks[0] = "http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/uk/4164613.stm";
theSummaries[1] = "Blair to face MPs amid feud talk";
theSiteLinks[1] = "http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/uk_politics/4166625.stm";
theSummaries[2] = "Alarming ignorance of cancer risk";
theSiteLinks[2] = "http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/health/4164131.stm";
theSummaries[3] = "Boscastle awaits flooding report";
theSiteLinks[3] = "http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/uk/4166895.stm";
theSummaries[4] = "'Errors' doomed first Dome sale";
theSiteLinks[4] = "http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/uk_politics/4165767.stm";
theSummaries[5] = "Police launch Class A drugs blitz";
theSiteLinks[5] = "http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/uk/4166925.stm";
theSummaries[6] = "Businessman takes top MI6 job";
theSiteLinks[6] = "http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/uk/4166941.stm";
theSummaries[7] = "'vCJD timebomb' fears discounted";
theSiteLinks[7] = "http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/health/4162749.stm";
theSummaries[8] = "Greer attacks 'bully' Big Brother";
theSiteLinks[8] = "http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/entertainment/tv_and_radio/4165101.stm";
theSummaries[9] = "Football: Morientes close to move";
theSiteLinks[9] = "http://news.bbc.co.uk/go/click/rss/0.91/public/-/sport1/hi/football/teams/l/liverpool/4127559.stm";
theSummaries[10] = "Tennis: Henman winning start";
theSiteLinks[10] = "http://news.bbc.co.uk/go/click/rss/0.91/public/-/sport1/hi/tennis/4164273.stm";
startTicker();
//-->
</script>
</body>
</html>
Can anyone see any stupid mistakes?
Cheers
Andy (mod)
andy@ultranerds.co.uk
IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates

