PDA

View Full Version : Interpret IE browser actions within in a webpage



rLarson
Apr 4th, 2005, 12:48 PM
I apologise upfront if the question below is in the wrong forum.

I've been asked to always save the contents of a form before a user navigates away. Using Javascript I can handle what happens when url's or links in a page are clicked... but what of the browser buttons etc.

When someone presses on the back button or closes a browser window?
I had the thought of using the "onunload" function to run a method that first saves the page... but I need to recognize what the user clicked to preceed where they intended.

What or how do I query/reference/capture this? ...

Any direction on this would be most appreciated. If this is the wrong forum to ask this, would you know where I should ask this?

Thanks again upfront for your time

-Ron

brothercake
Apr 4th, 2005, 04:57 PM
You can't - there are too many unreliable variables for this to work usefully; so many places it could fail. So you'll need to save the form data immediately, whenever it changes, instead of waiting til the last second.

Do you need info on doing that ..?

rLarson
Apr 4th, 2005, 05:22 PM
Yes thanks...
Any Info would be appreciated.

Basically,
The application I'm working on uses JSP's in a struts framework.

I had hoped to capture the user's browser event to recognize what to do once the form data was saved. I know it's an iffy thing filled with possible holes, but if I could at least know they hit the "back" button or "history" or closed the browser window.

Again, any info you can pass would help in some way -and-
again, thanks!

Ron

brothercake
Apr 5th, 2005, 04:14 PM
No you're misunderstanding me - you can save data in response to events on the forum - such as element "onchange", but you cannot reliably detect that a user is moving away from the page - refresh, history navigation, typing in another address - none of these things are reliably detectable because onunload doesn't always fire - it's a pretty sketchy event in most browsers.

So what I'm saying is to use the form events - the onchange on so on - to save the data, then when a person leaves the page, you already have it saved.