Hi Yizuhi,
aside from any technical solution to detect and mitigate the user closing the browser mid-session, you could think about the design of both your user interface and your datamodel/data persistence, in an attempt to avoid a user accidentily losing data.
On the user interface : if for some reason you feel like you have to let him enter multiple pieces of info in separate steps before saving any of that to permanent storage, make sure this is absolutely clear to the user, if the user expects he/she can leave after step 2 without losing any info entered, your UI failed at that. See for example widgets like a wizard, make sure user sees how many steps there are, make sure he can't mistake a button on step one as a save button if it isn't,...
On the design of the application : if there is so much data to enter that it can't be done in one step, but at the same time it logically belongs together as one thing and should be either complete or non-existent, you could consider still saving what you already have after each step, and add information in your datamodel about completeness (i.e. something like a status field on the main entity or a separate staging entity that only gets copied after the last step). This way, if a user accidentally stops half way, he could come back and find what was already entered and continue, and in the final step (where you now save all data entered for the first time), update the thing to reflect its completeness.
All this is of course complicating your application design a lot, and I think is only necessary if we are talking about large number of fields/steps and/or demanding users. I would imagine for most cases, making sure the user understands from the UI that he's not done yet should go a long way.
Dorine