Odd… Google with no search results or errors… Messenger: Due to a connection problem, changes you make might not be applied to other computers you use
Jul 11

If you’re working with web applications that use complex forms, you probably know that it becomes useful to split a very long forms on several pages (keeping interim posts on sessions variables) and process all the received data on a single transaction. But what happens when a user clicks on the Back button all the way to the first page or just wants to close the browser’s window?

Maybe you’ve already noticed those sites that warn your before closing the window? Wouldn’t it be useful, and a nice detail for the users, to let them know when something is about to get ruined because of a wrong click?

While looking for a way to implement this, I came up with onunload event but it didn’t solve the problem since the code would be executed after the user left the page. With a further research, I found that this can achieved using the onbeforeunload event from JavaScript.

On this simple example, the user is warned every time the the page is about to be changed, or the browser’s window closed (the example itself is a bit annoying). You might want to change it’s behavior so that when the proper button (or link) is pressed, the transition to the next page happens without the message (using page variables).

Leave a Reply

You must be logged in to post a comment.