[Slightly OT] Possible to detect if browser has regained focus?

Does anyone know of a way to tell if the browser has come back into focus? I’m specifically interested in the file download situation. Is it possible to detect that the Windows ‘Save As’ dialog box has been closed?

Thanks,

Bill