...

View Full Version : how do you call an External Js file in html?



LJackson
06-11-2008, 08:46 PM
Hi All,

I am new to javascript and i have used a piece of code from a tutorial on the web and have saved it as ticker.js however i cannot get it to work in the html code here is the ticker code
<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 9 June 08",
"New Store Added: Jamster - Misc - 8 June 08",
"New Store Added: iTunes - Entertainment - 2 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>

and i have used <script language="JavaScript1.2" type="text/javascript" source="ticker.js"> to call it but nothing appears can anyone tell what im doing wrong

thank you in advance
Luke

Philip M
06-11-2008, 08:53 PM
<script type="text/javascript" source= "ticker.js"> </script>

I take it that ticker.js is in the same directory as your .html file.

BTW, the time to say "thanks" is afterwards, not beforehand which gives the impression that you take other people's unpaid assistance for granted. Or as British politician Neil Kinnock put it, "Don't belch before you have had the meal." Prefer to use "please" beforehand and if you find a response helpful then you can use the "Thank You For This Post" button.

LJackson
06-11-2008, 09:00 PM
yeah it is in the same directory, and thank you for your code it works just as i wanted

cheers
Luke

LJackson
06-11-2008, 09:16 PM
is it possible to have parts of the ticker link to another site

using the same code above,

<code>
var mymessage = new initArray(
"Latest News: Site Updated 9 June 08",
"New Store Added: Jamster - Misc - 8 June 08",
"New Store Added: iTunes - Entertainment - 2 June 08",
"New Store Added: Butlins - Misc - 2 June 08"
);
</code>
is it possible to have Misc(in bold and green) link to a page in the same directory called Misc and is it possible to have the word misc appear in green font?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum