...

View Full Version : Is it possible to add colour and links to my news ticker (code included)



LJackson
06-11-2008, 09:58 PM
Hi All

I Have a news ticker and cannot manage to add a link nor change the font colour of parts of the ticker.

the code is:
<code>
<!--
// please keep these lines on when you copy the source
// made by: Nicolas - http://www.javascript-page.com

var tags_before_clock = "";
var tags_after_clock = "";
var speed = 100;
var speed2 = 2000;

function initArray() {

this.length = initArray.arguments.length;
for (var i = 0; i < this.length; i++) {
this[i] = initArray.arguments[i];
}
}

var mymessage = new initArray(
"Latest News: Site Updated 11 June 08",
"New Store Added: Betterware - Misc - 10 June 08",
"New Store Added: Jamster - Misc - 8 June 08",
"New Store Added: Butlins - Misc - 2 June 08"
);

var mymessage2 = mymessage;
var x = 0;
var y = 0;

if(navigator.appName == "Netscape") {
document.write('<layer id="ticker"></layer><br>');
}

if (navigator.appVersion.indexOf("MSIE") != -1){
document.write('<span id="ticker"></span><br>');
}

function upticker(){

if (y > mymessage2.length - 1) {
y = 0;
setTimeout("upticker()",speed);
}

else{

if (x > mymessage2[y].length) {
mymessage = mymessage2[y];
x = 0; y++;
setTimeout("upticker()",speed2);
}

else {
mymessage = mymessage2[y].substring(0,x++);
setTimeout("upticker()",speed);
}

if(navigator.appName == "Netscape") {
document.ticker.document.write(tags_before_clock+mymessage+tags_after_clock);
document.ticker.document.close();
}

if (navigator.appVersion.indexOf("MSIE") != -1){
ticker.innerHTML = tags_before_clock+mymessage+tags_after_clock;
}
}
}

setTimeout("upticker()",speed);
//-->
</code>
The text in bold i want linked to a page in the directory called misc.html and i want the text colour red, is this possible.

Philip M
06-11-2008, 10:24 PM
If you look at the original version, you will see that you can add html tags at

var tags_before_clock = "";
var tags_after_clock = "";

"If you want to customize your text in any way (color, size, center, etc.), put in the appropriate beginning and ending HTML tags in these two sections."

e.g:

var tags_before_clock = "<font face = "Arial" color = "red"><big>";
var tags_after_clock = "</color></big></font>";


But this is an old script (1999?) and these days the <font> tag is deprecated.

LJackson
06-11-2008, 10:40 PM
Hi Philip,

I think if i enter tags where you said it would link all the text and make the entire sectence red? i only want a couple of words red and linked within each sentence, i might be wrong tho

Philip M
06-12-2008, 08:59 AM
Try building it into the message text:-

<font color = "blue"><b><a href = http://www.yourdomain.com/page.html>misc</a></b></font>

or create a new variable

var tags_before_misc = "<font color = 'blue'><b><a href = http://www.yourdomain.com/page.html>"

and build up your message thus:-

ticker.innerHTML = tags_before_clock + mymessagePART1 + tags_before_misc + "MISC" + tags_after_misc + mymessagePART2 + tags_after_clock;

As I say, this is old code containing deprecated elements which may not be supported in future browsers. It would be best completely re-written using CSS.

LJackson
06-12-2008, 03:12 PM
Hi Philip

unfortunatly this didn't work like you say the whole thing probabily needs re-writing in CSS,( i had better start learning css :) ) never mind

Thanks For Your Time and Help
Luke



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum