1

I hope if 'attendance_20121029.xml' file is changed, web browser will be changed automatically. So I used setinterval method. But if I change the file, the web browser doesn't change. And if I execute the HTML file again, the web browser is changed. If anyone has some good idea, comment please.

<html>
  <head>
  </head>
  <body onLoad="tid=setInterval('refresh()',1000);">
    <script language="JavaScript">
    function refresh()
    {
        var xmlDoc=null;
        if (window.ActiveXObject)
        {
            xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
        }
        else if (document.implementation.createDocument)
        {
            xmlDoc=document.implementation.createDocument("","",null);
        }
        else
        {
            alert('fail');
        }

        if (xmlDoc!=null)
        {
            xmlDoc.async=false;
            xmlDoc.load("studentlist.xml");
        }
        var xmlDoc2=null;
        if (window.ActiveXObject)
        {
            xmlDoc2=new ActiveXObject("Microsoft.XMLDOM");
        }
        else if (document.implementation.createDocument)
        {
            xmlDoc2=document.implementation.createDocument("","",null);
        }
        else
        {
            alert('fail');
        }

        if (xmlDoc2!=null)
        {
            xmlDoc2.async=false;
            xmlDoc2.load("attendance_20121029.xml"); 
        }



        document.write("<table border='1' cellspacing='4' cellpadding='4'>");
        document.write("<tr><th>");
        document.write("Student Name");
        document.write("</th>");
        document.write("<th>");
        document.write("Attendece");
        document.write("</th></tr>");
        for (i=0 ; i<xmlDoc.childNodes[1].childNodes.length ; i++)
        {
          document.write("<tr>");
          document.write("<td align='center'>");
          document.write(xmlDoc.childNodes[1].childNodes[i].text);
          document.write("</td>");
          document.write("<td align='center'>");
          for (k=0 ; k<xmlDoc2.childNodes[1].childNodes.length ; k++)
          {
            if(xmlDoc.childNodes[1].childNodes[i].text == xmlDoc2.childNodes[1].childNodes[k].tagName)
            {
                document.write("O");
                break;
            }
          }
          if (k == xmlDoc2.childNodes[1].childNodes.length )
          {
            document.write("X");
          }

          document.write("</td>");
          document.write("</tr>");
        }
        document.write("</table>");
        document.close();
    }

</script>


  </body>
</html>
Jimmy
  • 473
  • 5
  • 9
  • 13
  • Does it work better if you write ``? It's practically never right to put a function call in a string as the argument to setInterval, it should be a function name. – Barmar Oct 30 '12 at 05:57

0 Answers0