unload for close not refresh

D

DonO

I have a jsp page that updates information as a user enters form
fields. It's part of an AP system where a user can select a category,
and then it refreshes the page, pulling relative info into other form
fields.

The issue we have is that closing the window with the [x] closer does
not clear out buffered info. We have a "close" button that will do
this. I tried doing an "onunload" to call the same function as the
close button, but since the form is reloaded as the user tabs through
fields, it calls the onunload and the window closes.

Does anyone have an idea of how to call the close function when the
window closes, but not when it reloads?

Thanks for any help.

D.
 
M

Michael Winter

I have a jsp page that updates information as a user enters form
fields. It's part of an AP system where a user can select a category,
and then it refreshes the page, pulling relative info into other form
fields.

The issue we have is that closing the window with the [x] closer does
not clear out buffered info. We have a "close" button that will do
this. I tried doing an "onunload" to call the same function as the
close button, but since the form is reloaded as the user tabs through
fields, it calls the onunload and the window closes.

Does anyone have an idea of how to call the close function when the
window closes, but not when it reloads?

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
 
D

DonO

Michael Winter said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top