See http://stackoverflow.com/questions/3888902/javascript-detect-browser-close-tab-close-browserhttps://stackoverflow.com/questions/3888902/javascript-detect-browser-close-tab-close-browser for a more generic asking of the same question.
Also consider saving full game on floor changes, and incremental deltas on each move. Then you can replay the game up to the point of last move.
Assuming there is some use of random number generators, you can generate and re-seed the random number generator at the start of each new floor, and then save it along with the floor. Then you can reseed on load, and should be able to replay the moves with the same sequence up to the last one done.