This is a warning that Firefox raises when I want to leave certain pages. Based on the pages I’ve seen this on and that this warning appears when I try to close the page after filling in the forms, I can only assume that it’s working on a dynamic page. Which technology is used to implement this functionality? How can I implement it myself on a simple hello-world page?
Share
You basically implement a handler for
beforeunloadevent. This allows you to warn your users that they have unsaved data.Pseudo Code:
Here’s a very good article that discusses this in depth:
http://www.4guysfromrolla.com/webtech/100604-1.shtmlNote: This link no longer exists. Here is a copy of it from the Wayback Machine:https://web.archive.org/web/20211020134123/http://www.4guysfromrolla.com/webtech/100604-1.shtml
Note: There is
onunloadevent also but that fires after the page has unloaded, hence is too late to take any reliable action. You should never put any critical code inonunloadas that is never guranteed to execute.