View Full Version : Javascript and Netscape (?)

kid A
03-30-2003, 11:19 PM
Hi everbody,

i have a problem with a javascript script.
it doesn't work well on Netscape 6x-7 (on both Win and Mac) and also on
Explorer 5x (Mac).

I modified the original version and i could get some improvements (also on
now it works better, but it still doesn't display the Alert message
The script looks like that:

<script LANGUAGE="Javascript">

function suddenExit(e)
if(!e) e = window.event;
if (py<0){
if(e.preventDefault) e.preventDefault()
else e.returnValue=true

event.returnValue="ATTENTION! By closing the window in this way, the
system will not save the data \n If you...etc etc

//alert(py + "If you exit, tour data wil not be correctly registered!")

function warn_dataLoss(){
if(navigator.userAgent.toLowerCase().indexOf("msie")==-1 || window.opera){
alert("Data will be lost");


<body .... onbeforeunload='suddenExit(event)'

- on IE 5x/mac (the message is displayed cut up at the 2nd line) at page
- on both IE5x/mac and NN 6x-7/win+mac
the Alert is displayed only while Refreshing, NOT while Closing the
window (as it should do!) ???

I know that the event "onbeforeunload" only works on IE/win;
but the other event handler "onunload" should fire while exit/closing the
But, it does not .... !!!
How could I fix this problem,and get yhe script really "crossbrowser" ?

Bye, thanx in advance

If you need to see the whole Script (or the page - which is a Popup window -
that contains the script), tell me and I'll post it.
(...sorry 4 my english...)

04-01-2003, 09:13 AM
I tried this in a few different mozilla builds (ns6,ns7, phoenix) and it kinda comes and goes - sometimes it works, sometimes not.

I'm not too sure of the reason why it sometimes wouldn't work; I was always 'brought-up' thinking onunload is an unreliable event, and not to use it.

So unless someone knows better than this, my advice is not to rely on those events for what you're doing.

What are you doing? You need to make sure that data has been saved before page exit? Can you save the data automatically, something like that?

kid A
04-01-2003, 10:32 PM
thanx for your reply!

for more details about the script:

- the script is included in a Popup-window (launched by the Home of the
site, accessed by Login/pwd)
and this Popup hanles an online Test, with muliple questions, that you go
thru 'til you reach th eresukts and th evaluation.
Th e whole Popup (sample), if that might help, is in the Attachment
[The code is partly in italian..if that's a problem, i'll translate it ]

- what i need is to make the user sure that, if he closes the Popup-window
before finishing th eTest, the data of his Test will not be saved by the
system and he must restart the test back from the beginning;
the advice shuold also suggest that the correct way to quit the Test without
losing data is to click the Cancel-button of the DialogBox(shown when he
tries to close the Popup) and the the Exit-button in the Popup .
So, like this:
" Attention: by closing the window this way, the system will NOT
saveyour data and it will not be possible to go on ith the Test lately.
To save your data, you MUST click on CANCEL (Annulla) in this window[= i.e.the DialogBox !] and then EXIT (Esci) in the main window[= i.e. the Popuup window which handles the Test]
Only in this way, the system will show your evaluation score"

(this message is correctly shwon only on Explorer/win, as far as i know,
'cuase it's handled by Event "onBeforeunload")

So that's why i'm trying to get an Alert message before page exit also on
Ns/win (and Ns/mac as well as Explorer/mac) !!??

You seem to suggest to drop those events like "onunload"...but which
other kinda Events shuold i take into consiferantio to get what
"onbeforeunload" and "onunload" would do ?
i'm clueless...

04-02-2003, 10:50 AM
Yeah I can see where you're coming from - the problem is that even if onunload were reliable, the alert doesn't happen until after the window is closed.

I can't give you a concrete technical answer; I've never tried to take such control over a window. What I would do is either make it clear at the start of the test that only completed tests will be saved, or auto-save yourself after each question.

kid A
04-02-2003, 10:32 PM
what do you mean with :

Originally posted by brothercake
auto-save yourself after each question. ?

Is there really no way to get on Netscape the same (or, at least, quite the same) as it happens on Explorer with the onBeforeunload event?


kid A
04-13-2003, 03:20 PM
i do hope you ain't forgotten me.....:)

give me a sign;)

04-13-2003, 04:05 PM
Well you mentioned "save the data" - that means you must have a process by which you save the data; if it's in javascript you could do that automatically instead of waiting for the user to hit submit.

kid A
04-13-2003, 06:03 PM
i guess the Autosave should be obtained modifying the server-side (ASP) scripts...which i actually can't access
(and i'm not keen on SP)

do you have some other ideas?

thanx !

09-27-2005, 07:50 PM
You could use AJAX. http://developer.mozilla.org/en/docs/AJAX