Thursday, June 26, 2008

Use xmlHTTPRequest for Accessing Local Files

here are some of my experiences working with xmlHTTPRequest object to open local files.
xhr.open("GET",localFile,false);          
httpRequest.onreadystatechange = function(){
if (xhr.readyState == 4) {
if (xhr.status == 200) {
//blahblah...
} else {
//blahblah...
}
}
xhr.send(null);


First of all, there will be exceptions if you trying to access a local file that doesn't exist. Instead of returning 404 status code, it throws out an exception. In addition, the status code from opening local files will be 0. Below is quote from Mozilla website for xmlHTTPRequest object.

file:/// and ftp:// do not return HTTP status, which is why they return zero for status and an empty string for statusText. please refer to bug 331610 for more insight.

I didn't find any IE related document to xmlHTTPRequest object, but from my test, it also return 0 for file:///.

Below is the modification to original code
try {
xhr.open("GET",localFile,false);
httpRequest.onreadystatechange = function(){
if (xhr.readyState == 4) {
if (xhr.status < 300) {
//blahblah...
} else {
//blahblah...
}
}
}
xhr.send(null);
} catch (ex) {
//blahblah...
}


Read more!

Wednesday, June 25, 2008

FireFox 3 is out

Good news that FireFox 3 is out, and I think it cheers a lot of geeks. But I will still keep using FireFox 2 for a while until FireBug is integrated with FireFox 3 smoothly. During the FireFox 3 beta testing, a lot of people has found a lot of issues using FireBug. In addition, Mozilla has reported a minor vulnerability in FireFox 3 and its earlier version.
Read more!

Does FireFox support beforeunload event?

The answer is yes. FireFox does support beforeunload event. However, you can't expect it to work if you put its event handler into the <body> tag as we do in IE.
In IE, there are several ways to define the onbeforeunload event handler


(1)<body onbeforeunload='confirmExit();'>

(2)document.body.onbeforeunload=confirmExit;

(3)window.onbeforeunload=confirmExit;

function confirmExit(){
return "You are about to leave this page. Are you sure?";
}

in FireFox, you can only use the (3) to trigger the unbeforeunload event handler. It frustrated me first, because I thought they are all same, but why I didn't get what I expected. I guess it is not supported very well and the first two approaches don't work in FireFox. So if you want to use onbeforeunload, please use the (3) to make it work on both IE and FireFox.

Read more!

Monday, June 16, 2008

My First Father's Day

I felt so great about getting my first father's day gift


"Dear Daddy,

Even though I haven't see you, I can hear your voice and feel your touch. Thank you for taking good care of me and mommy, and I can't wait to hug you and kiss you when I come out to the world!
Happy Father's Day!

Love,
Mengmeng"
Read more!

Monday, June 9, 2008

A nice Joomla debugging extension

I have been looking for some kind of logging framework for Joomla development, that is similar to log4j, but I couldn't. So I came across this article talking about J!Dump. Looks like it might be helpful.
Read more!