Jump to content

Works in IE, but not in FireFox and Netscape, help please!!!


greg

Recommended Posts

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')">

 

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.