Javascript reading .txt file and displaying in HTML -
i'm trying have javascript on html page read .txt file (status.txt) in same directory , display contents in 2 different font colors based on information in .txt file. have displaying text on page fine, wanted make bit more noticeable. here current code display text basic #ccc hex.
<script type="text/javascript"> loadxmldoc(); </script> <script type="text/javascript"> function loadxmldoc() { var xmlhttp; if (window.xmlhttprequest) { xmlhttp = new xmlhttprequest(); } xmlhttp.onreadystatechange = function() { if (xmlhttp.readystate == 4 && xmlhttp.status == 200) { document.getelementbyid("status").innerhtml = xmlhttp.responsetext; } } xmlhttp.open("get", "status.txt", true); xmlhttp.send(); } </script> <h3 id="status" style="padding-right: 7px; padding-left: 7px; margin-top: 2px; font-size: 11px; color: #cccccc"> status </h3>
the text file contents overwritten every time .vbs file ran. either say:
6/11/2016 8:58:30 script started
or
6/11/2016 9:31:12 script stopped
the thing changes timestamp. text display red when says "(timestamp) script stopped" , green when says "timestamp) script started". if help, that'd great!
var color = xmlhttp.responsetext.indexof('started') !== -1 ? 'green' : 'red'; document.getelementbyid("status").innerhtml = '<span style="color: ' + color + '">' + xmlhttp.responsetext + '</span>';
Comments
Post a Comment