Function call

They have: 39 posts

Joined: Jun 2000

when user close a window using file menu or using any other method, is it possible to call a JavaScript function?

Vincent Puglia's picture

They have: 634 posts

Joined: Dec 1999

easy answer -- not really

They have: 39 posts

Joined: Jun 2000

Thanks, but can you please expalain your answer.

Vincent Puglia's picture

They have: 634 posts

Joined: Dec 1999

Hi

As far as I know, there is no event handler that can trap the browser's buttons. You might make the window full-screen so the browser is not readily-accessible, but that only hinders clicking them.

What are you trying to do?

Vinny

Where the world once stood
the blades of grass cut me still

They have: 39 posts

Joined: Jun 2000

I am writting one application, I have lots of data in the memory, users can save data in the memory before writing to the database, so in case if user try to close window without saving data to the database, I want to throw an error message.

One possibility is to use onUnload event, but its going to call that event if user try to go to another page, that not what I want to do, I want to call a JavaScript function only when user tries to close that window.

Vincent Puglia's picture

They have: 634 posts

Joined: Dec 1999

Hi,

You would be better served with a server-side solution -- a perl script (or somesuch) that checks the server status codes -- or a server session variable.

Vinny

Where the world once stood
the blades of grass cut me still

They have: 231 posts

Joined: Feb 2000

The best thing to do in this situation is to use a popup window. Collect your data in this window then close it manually after the user has finished.

You can set the 'onUnload' event handler to check when closing the window that the form has been sucessfully completed. If you need more help I can explain further.

:: Lloyd Hassell :: http://www14.brinkster.com/lloydh ::

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.