I know I can use connection_aborte开发者_高级运维d() to explicitly check if the browser closed but then I have to check at discrete points and the browser may close in between my checks.
Is there an exception or something I can catch (I couldn't find one). I have some processes that may run long and if someone shuts down the browser, and thus aborts the process, I just want to log that such a thing happened.
You can't tell if the browser shut down, as HTTP is a stateless protocol. Checking if the connection terminated tells you (usually) if the user lost connection or aborted during page loading. You can only check for closing the browser client-side using JavaScript.
No. The browser does not have to tell the server that it is about to close a connection. You can try to simulate it with JavaScript pings, but even that is more than error-prone.
精彩评论