I've already tried to use unload, but it seems like that it is too late to do the checking in the unload event. The page would be refreshed whether the user chooses OK or Cancel.