www.statehousenews.com/beta/scroller2.asp
Is a code I wrote that retrieves data from a txt file and displays it into a txt scroller. XMLhttpRequest( ) is used to open and retrieve the data. The javascript works fine in IE7 but doesn't work at all for Firefox/2.0.0.13.
Here's the code:
[HTML]<%@LANGUAGE="VB SCRIPT" CODEPAGE="65001 "%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitl ed Document</title>
</head>
<body>
<script type="text/javascript">
<!--Custumazible Java Applet-->
var line=new Array()
var txtFile = new XMLHttpRequest( );
txtFile.open("G ET", "http://www.statehousen ews.com/public/scroller2.txt", true);
txtFile.onready statechange = function()
{
if (txtFile.readyS tate === 4)
{ // Makes sure the document is ready to parse.
if (txtFile.status === 200)
{ // Makes sure it's found the file.
document.write( "Yes, we found the file");
allText = txtFile.respons eText;
document.write( allText)
linesFed = txtFile.respons eText.split("\n "); // Will separate each line into an array
}
document.write( linesFed[1]);
counter = 0;
for(var t = 1; t<=linesFed.len gth; t++)
{
line[t] = linesFed[counter];
counter = counter + 1;
}
}
}
txtFile.send(nu ll);
// Specify font size for scroller below **This is where my code txt scroller start.
var ts_fontsize="12 px"
var longestmessage= 1
for (i=2;i<line.len gth;i++){
if (line[i].length>line[longestmessage].length)
longestmessage= i
}
//Auto set scroller width
var tscroller_width =line[longestmessage].length
lines=line.leng th-1 //--Number of lines
//if IE
if (document.all|| document.getEle mentById){
document.write( '<form name="bannerfor m">')
document.write( '<input type="text" name="banner" size="'+tscroll er_width+'"')
document.write( ' style="backgrou nd:url(images/Layout_7.jpg) no-repeat; color: '+document.body .text+'; font-family: verdana; font-size: '+ts_fontsize+' ; font-weight:700; border:none" onfocus="blur() ">')
document.write( '</form>')
}
temp=""
nextchar=-1;
nextline=1;
cursor="|"
function animate(){
if (temp==line[nextline] & temp.length==li ne[nextline].length & nextline!=lines ){
nextline++;
nextchar=-1;
document.banner form.banner.val ue=temp;
temp="";
setTimeout("nex tstep()",2000)}
else if (nextline==line s & temp==line[nextline] & temp.length==li ne[nextline].length){
nextline=1;
nextchar=-1;
document.banner form.banner.val ue=temp;
temp="";
setTimeout("nex tstep()",2000)}
else{
nextstep()}}
function nextstep(){
if (cursor=="|"){
cursor=" "}
else if (cursor==" "){
cursor="|"}
else if (cursor=="|"){
cursor=" "}
else if (cursor==" "){
cursor="|"}
nextchar++;
temp+=line[nextline].charAt(nextcha r);
document.banner form.banner.val ue=temp+cursor
setTimeout("ani mate()",75)}
//if IE 4+ or NS6
if (document.all|| document.getEle mentById)
window.onload=a nimate
// -->
</script>
</body>
</html>[/HTML]