Saturday, September 12, 2009

Why the javascript beforeunload event is incomplete

The onbeforeunload event fires when a page is being unloaded.

In the intranet webapplications world customers pretty often ask to show a warning when a user leaves a page (by closing the browser, closing a tab, clicking a link,..). This feature is specifically very interesting for data-input-driven webforms where one wrong click can make ten minutes of work undone.

Last week I had to implement this feature in a huge webform which is causing lots of postbacks (firing the onbeforeunload event). Actually I only had to warn the user when they closed the browser or clicked a link in the masterpage. I figured out that the beforeunload event must have some convenient properties, but as you can see below, it had no properties which I could use.



Offcourse there are workarounds for this problem, like there are workarounds for almost all technology problems. But these workarounds often make tasks harder and less "clean".

In my opinion the browsers could and should do something about this. Adding a few properties like unloadedbysrc, unloadedbytag, unloadedbyid would make our life a tad easier.

What do you think?

2 comments:

  1. Groot gelijk seppe. Da zou het leve er echt gemakkelijker op make xD.

    Je vriend Frederik

    ReplyDelete
  2. Blij dat ge het met mij eens zijt Frederik ;)

    ReplyDelete