Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > unload for close not refresh

Reply
Thread Tools

unload for close not refresh

 
 
DonO
Guest
Posts: n/a
 
      03-02-2004
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.
 
Reply With Quote
 
 
 
 
Michael Winter
Guest
Posts: n/a
 
      03-02-2004
On 2 Mar 2004 14:45:23 -0800, DonO <(E-Mail Removed)> wrote:

> 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

--
Michael Winter
http://www.velocityreviews.com/forums/(E-Mail Removed)d (replace ".invalid" with ".uk" to reply)
 
Reply With Quote
 
 
 
 
DonO
Guest
Posts: n/a
 
      03-03-2004
Michael Winter <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to close a TCP socket? (TCPSocket#close doesn't close it) IƱaki Baz Castillo Ruby 7 01-12-2010 01:32 PM
file.close() does not really close under Windows? Dani Python 3 12-17-2009 02:49 PM
this.Connection.Close(); does not close the Oracle session! Pleasehelp! S_K ASP .Net 6 12-07-2007 02:07 PM
call a function on page close NOT unload Donkey Cart Racer Javascript 1 07-05-2006 08:17 PM
Browser Close / New URL / Form UnLoad() Al Fraser Javascript 1 09-30-2003 04:25 PM



Advertisments