greg Posted February 2, 2007 Share Posted February 2, 2007 I have the following code to get the Page Load Time from visitors. I get this var passed to php thru XMLHttpRequest and write the log. Everything in Internet Explorer works good, however in Netscape (7.2 tested) and FireFox (2.0.0.1 tested) it does not work. I don't have too much experience in these languages, could anyone give me some ideas about what should I do to get this code works in these browsers? Thank you! Greg <SCRIPT LANGUAGE="JavaScript"> var referer = "<?= $referer ?>"; //referer var ip = "<?= $b_ip ?>"; // ip address var uri = "<?= $uri ?>"; // url requested var lang = "<?= $b_lang ?>"; // language var width = screen.width; var height = screen.height; if (typeof(PLT_BackColor)=="undefined") PLT_BackColor = "white"; if (typeof(PLT_ForeColor)=="undefined") PLT_ForeColor= "black"; if (typeof(PLT_DisplayFormat)=="undefined") PLT_DisplayFormat = "%%S%% "; if (typeof(PLT_FontPix)=="undefined") PLT_FontPix = "12"; if (typeof(PLT_DisplayElementID)=="undefined") PLT_DisplayElementID = ""; dt=new Date(); document.onreadystatechange=function() { if (document.readyState=="complete") { if ((PLT_Span=document.getElementById(PLT_DisplayElementID)) == null) { document.body.insertBefore(document.createElement("br")); PLT_Span = document.body.insertBefore(document.createElement("span")); } PLT_DisplayFormat = PLT_DisplayFormat.replace(/%%S%%/g, ((new Date() - dt)/1000)); PLT_Span.style.Color = PLT_ForeColor; PLT_Span.style.backgroundColor = PLT_BackColor; PLT_Span.style.fontSize = PLT_FontPix + "px"; PLT_Span.innerText = PLT_DisplayFormat; } } </SCRIPT> <script type="text/javascript"> var xmlhttp dt=new Date(); function loadXMLDoc(url) { xmlhttp=null // code for Mozilla, etc. if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest() } // code for IE else if (window.ActiveXObject) { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP") } if (xmlhttp!=null) { xmlhttp.onreadystatechange=state_Change xmlhttp.open("GET","log_write.php?date=" + PLT_DisplayFormat + " | " + ip + " | " + dt + " | " + referer + " | " + width + " x " + height + " | " + navigator.appName, true) xmlhttp.send(null) } else { alert("Your browser does not support XMLHTTP.") } } function state_Change() { // if xmlhttp shows "loaded" if (xmlhttp.readyState==4) { // if "OK" if (xmlhttp.status==200) { document.getElementById('T1').innerHTML=xmlhttp.getAllResponseHeaders() } else { alert("Problem retrieving data:" + xmlhttp.statusText) } } } </script> </head> <body onload="loadXMLDoc('images/infobox/finished.gif')"> Quote Link to comment Share on other sites More sharing options...
fenway Posted February 2, 2007 Share Posted February 2, 2007 What about it does work? Quote Link to comment Share on other sites More sharing options...
greg Posted February 2, 2007 Author Share Posted February 2, 2007 come again please? Quote Link to comment Share on other sites More sharing options...
fenway Posted February 2, 2007 Share Posted February 2, 2007 Well, if statements can't not work, and there's a lot of code there... where's the problem, specifically? Quote Link to comment Share on other sites More sharing options...
greg Posted February 2, 2007 Author Share Posted February 2, 2007 Thank you. The code works correctly in IE. In Netscape and FireFox it displays this alert: alert("Problem retrieving data:" + xmlhttp.statusText) I know this is correct. If document.getElementById('T1').innerHTML=xmlhttp.getAllResponseHeaders() does not work, it should give the alert, but I want know is if there is anyway to make the code compatible with Netscape and FF so I can get the page load time from then as I get it from IE. Thank you for your time. Quote Link to comment Share on other sites More sharing options...
mainewoods Posted February 2, 2007 Share Posted February 2, 2007 the 'innerText ' attribute is supposed to be ie available only: PLT_Span.innerText you should be able to check whether it is available on a particular browser like this: if (!PLT_Span.innerText) alert('**innerText not available on this browser*"); http://www.hanselman.com/blog/AJavaScriptImplementationOfInnerTextNotInnerHtmlForFireFoxAndNonIEBrowsers.aspx Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.