Michael Winter <M.******@blueyonder.co.invalid> wrote in message news:<op**************@news-text.blueyonder.co.uk>...
That cannot be done reliably. onunload is called at different times by
different browsers and some, like Opera, do not fire onunload when the
browser is closed.
Even if it were, it is highly unlikely that anything you do will actually
have an affect as a browser probably won't open a connection to a server
when the user is trying to close it.
Instead, impress upon your users the importance of sending their data
before closing their browser.
Mike
Thanks for the reply Mike. Fortunately (I suppose) this is for an
internal project, so I know all my users will be using IE 5.5 or
higher.
I did find something that works, but is really ugly...
I added a new form at the bottom of the page named close_check with a
hidden field with the name "close_me" and default value "1" (true).
I put in a call to a function called "tabCheck()" in all the places
where the tabbing forces the page to reload. This function would set
the "close_me" value to "0" (false) like this:
document.form_check.close_me.value = 1;
My onunload then called a function to which checked the value of
"close_me" if it was "1" it did the close, otherwise, it set the value
back to "1".
So the order of how things happen is:
1) User tabs over fields that reload page
2) "close_me" is set to false
3) onunload function is kicked off
4) Because the close_me value is false, it does NOT close the window
Other scenario:
1) User clicks the [x] to close the window
2) onunload function is kicked off
3) Because the value is set to 1 by default, or at the end of checking
it above, it is true, and the close function is called, just as if
they clicked the "Close" button we have on the page.
So far it seems to work. If anyone has any better ideas, I'm open to
suggestion. For now, with IE this option is ok.
Thanks again,
D.