There's an alternative but it's expensive and also really depends on the user case. It works wonders for me at a simple chat we did. You can have the javascript to constantly (every few seconds) call a page with the user id, example.com/misc/alive/456457
, where 456457 is the id of the user. You introduce then that call in a database table as a new row. If the user doesn't call back in more than X seconds, you assume he's gone.
Of course, you don't get an action just when the user 'is gone', you just get a database that then you've got to analyse to know when the user 'probably' left. For the chat example, it was as easy as calling it every 2 seconds and then checking if there was any user online in the last 5 seconds and delete duplicate ids (to give it some threshold).