Thursday, January 20, 2005

First Post - Firefox fights

I really don't know what to write on my first post, but Joel says I should write one (great article, by the way. As usual. I should really get to read the JoS book sometime), so I guess I should just start.

Today I stayed late since I go to the Achla meeting, and Sefi was kind enought to pick me.

Anyway, I just had a big fight with Firefox today. First of all, it insists on blocking my popups, no matter what I tell him. I wonder if this is because I have TBE installed. I guess I need to reinstall a clean Firefox so I can blame all the weird behaviors I found on it. I don't use it as my day-to-day browser anyhow. (I really love Avant Browser. I do hope that the little features I still miss will be entered soon.) I also tried to install a different theme, but failed. At first the themes page didn't loaded, and then it claimed the jar file is corrupted. I really don't know how all of the geeks keep up with this crap. It is event worse than MS problems.

The real problem was getting the update via XMLHttpRequest to work.

Our code looks like this:

function getXMLHTTP()
{
try
{
return new ActiveXObject("Msxml2.XMLHTTP")
}
catch(e)
{
try
{
return new ActiveXObject("Microsoft.XMLHTTP")
}
catch(oc)
{
}
}

return (typeof XMLHttpRequest == "undefined") ? null : new XMLHttpRequest();
}

function updateEventList(szJSUpdateCode)
{
if(gXMLHTTP.readyState == 4)
{
if(gXMLHTTP.responseText && gXMLHTTP.responseText.charAt(0) != "<")
{
eval(gXMLHTTP.responseText); // call retrieved JS code to get events
} else {
alert("Failed to download '" + gszURL + "'");
}
gszURL = null;
}
}

var gXMLHTTP = null;
var gszURL = null;
function sendRequest(szURL)
{
if(gXMLHTTP == null)
gXMLHTTP = getXMLHTTP();

if(gXMLHTTP == null)
return false;

if(gXMLHTTP.readyState != 0)
gXMLHTTP.abort()

gXMLHTTP.onreadystatechange = updateEventList;
gszURL = szURL;
gXMLHTTP.open("GET", szURL, true); // true means work asynchronically
gXMLHTTP.send(null);
}
It is called from the main page to update the list, but when an event is being updated in popup, the popup called opener.sendRequest() with the updated URL, to update the list, and then window.close(). This works well in IE, but for some reason, Firefox decided to stop the download and set the readyState to true without any data in the time that popup closed itself. I don't know exactly why it is, but the solution was to write:
function delayedRequest(szURL)
{
setTimeout("sendRequest('" + szURL.replace(/\'/g, "\\\'") + "');", 1);
}

And make the popup call delayedRequest.

0 Comments:

Post a Comment

<< Home