Applet Works For Ie But Doesn't For Firefox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ktang
    New Member
    • Apr 2008
    • 1

    #1

    Applet Works For Ie But Doesn't For Firefox



    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]
    Last edited by gits; Apr 6 '08, 10:21 AM. Reason: added code tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    You have an error on line: [code=javascript]var tscroller_width =line[longestmessage].length[/code]

    There are a few problems with the script. You're making an asynchronous request, but expecting the result immediately afterwards. You're also using document.write( ) after the page has loaded. Remove those since they're only for testing.

    All the code relating to the line array should be when the response is ready in the onreadystatecha nge function, not outside it.

    Comment

    Working...