Testing:

Firefox and IE behavior on
javascript "onBeforeUnload" event

UPDATE:

Originally I was returning the prompt via this line:
event.returnValue="are you sure?"
I copied those pages to make 5 more once I found a resource that showed that the standard is actually to have this line for the return value:
return "are you sure?"
Whereas IE was okay with the former in some cases, (play with IE and #1 - #5) it didn't like anything at all with the latter, except the apparently correct way (Try #10, below). Firefox only will recognize one way of doing this, (#10 below) so it's my assumption that it is the proper, right, and good method for writing javascript. WTF is event.returnValue for?

Originally, I wrote:

The links below SHOULD (by all accounts I've read up on) ask you if you really want to leave (unload the page).

I've tried both with
window.onbeforeunload=ConfirmClose 
inside the <SCRIPT> tag and, and with
onBeforeUnload="ConfirmClose();"
inside the <body> tag. (and both at the same time) It seems only to work in IE, and I did happen to notice that in the body tag, capitalization doesn't matter, but in the SCRIPT tag, it must all be lowercase, except for the function which is triggered by the firing of the event.


Click a link below to play:

Using event.returnValue as suggested by many many pages
First try (Mix-case body tag only)
Second try (Mix-case body tag @!#$% AND script tag)
Third try (Mix-case script tag only)

#4 try (Everything Lowercase, body tag)
#5 try (Everything Lowercase, script tag)


NOW, without event.returnValue (using return)
#6 try (Mix-case body tag only)
#7 try (Mix-case body tag @!#$% AND script tag)
#8 try (Mix-case script tag only)

#9 try (Everything Lowercase, body tag)
#10 try (Everything Lowercase, script tag)



Author's Note:

The reason I've put time and effort into dicking around with this so much is that I work in a place that is so monolithic that it only allows Internet Exploder on its workstations. I tried to convince a few people how good Firefox is, but soon realized that I was preaching (or was I singing?) to the choir, they like Firefox too. They use it at home. They want it there at work. But for some strange reason, it's just not okay. Anyway, I have a need for a web application (for ssh, of course) to be INSISTENT on confirmation before unloading the page. And, since I use IE there, and Firefox or Safari on other folks' machines, I really wanted my applet to work across the board.

(This is largely due to the fact that some idiot designed an IBM keyboard which features a browser "Back" button exactly where the left arrow key should be. And since my web app is console SSH, it's only normal to pinky over and hit the left arrow button every now and then, right? $#&%!, I just killed my session!)

SO, I figure, since I've put SO MUCH TIME into this already, I'd take another hour or so and make a stylesheet, throw in some <h1> and such. Maybe someone will find this and it will help them. Some day I might even feel like making it xhtml 1.0 strict. Yeah... Maybe... Or not.

Don't let the bastards get you down!

Cheers!