code works very fine in i.e but not in firefox and chrome

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • simum
    New Member
    • Mar 2013
    • 4

    code works very fine in i.e but not in firefox and chrome

    This code works very fine in i.e but not in firefox and chrome
    Code:
    <html>
    <head>
    <script type="text/javascript1.2">
    
    var message="Welcome to my Page!";
    var neonbasecolor="gray";
    
    var neontextcolor="#F6EE0A";
    var flashspeed=100 ;
    var n=0
    
    if (document.all){
    document.write('<font color="'+neonbasecolor+'">')
    
    for (m=0;m<message.length;m++)
    document.write('<span style="font-size:25px;
     font-family:Georgia;" id="neonlight">'+message.charAt(m)+'</span>')
    
    document.write('</font>')
    var tempref=document.all.neonlight
    }
    
    else
    
    document.write(message)
    
    function neon(){
    if (n==0)
    {
    
    for (m=0;m<message.length;m++)
    tempref[m].style.color=neonbasecolor
    
    }
    
    tempref[n].style.color=neontextcolor
    
    
    if (n<tempref.length-1)
    n++
    else{
    n=0
    clearInterval(flashing)
    setTimeout("beginneon()",1500)
    
    return
    }
    }
    function beginneon(){
    if (document.all)
    flashing=setInterval("neon()",flashspeed)
    
    }
    beginneon();
    
    </script>
    
    </head>
    
    <body>
    </body>
    
    </html>
    Last edited by acoder; Mar 6 '13, 12:02 PM. Reason: Please use [code] tags when posting code
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    The main cause is your use of document.all. This is ancient code. Now you should use document.getEle mentById('eleme nt_id') to reference an element. You can also get rid of any checks for document.all - that obviously would exclude any browser which doesn't support it.

    I would abandon this code entirely and use a decent library/framework instead. The cross-browser legwork has already been done for you.

    Comment

    • simum
      New Member
      • Mar 2013
      • 4

      #3
      sorry acoder i can't catch up ur code can u please attach ur idea code in that script..

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        To be perfectly honest, this code is not worth saving. It's really old and has other flaws, e.g. the use of the font tag. I suggest you find alternative modern code. There's plenty out there that's already been written.

        If you insist on editing this code, you'll have to work on the suggestion and show an attempt yourself.

        Comment

        • Unkno
          New Member
          • Mar 2013
          • 9

          #5
          Code:
          <html>
          <head>
          </head>
          <body>
          <script ltype="text/JavaScript1.2">
          var message="Welcome to my Page!"
          var neonbasecolor="gray"
          var neontextcolor="#FB8836"
          var flashspeed=100  
          var n=0
          document.write('<font color="'+neonbasecolor+'">')
          for (m=0;m<message.length;m++)
          document.write('<span style="font-size:20px;" id="neonlight">'+message.charAt(m)+'</span>')
          document.write('</font>')
          var tempref=document.all.neonlight
          function neon(){
          if (n==0){
          for (m=0;m<message.length;m++)
          tempref[m].style.color=neonbasecolor
          }
          tempref[n].style.color=neontextcolor
          if (n<tempref.length-1)
          n++
          else{
          n=0
          clearInterval(flashing)
          setTimeout("beginneon()",1500)
          return
          }
          }
          
          function beginneon(){
          flashing=setInterval("neon()",flashspeed)
          }
          beginneon()
          
          
          </script>
          </h2>
          
          </body>
          </html>
          This code will work fine in all browsers
          Last edited by acoder; Mar 11 '13, 10:55 AM. Reason: Please use [code] tags when posting code

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            There are still a number of flaws with this code even if it does work in all browsers as you claim.

            I would suggest modernising your code. It'll be good practice for the future. Avoid using non-standard and deprecated code/elements.

            Comment

            Working...