Simulate onClick without click

Hi, this is my first post, I have a chat script wehere the user have to click a icon to leave, but some times (most of the times) they close the browser and the operator ignore it.
The close chat button its this one : <a class=“closethread” href=“javascript:void(0)” onClick=“return false;” title=“close chat”>Close Chat</a>.
The idea is…when the user close the browser a function onBeforeUnload trig the link to make the class “closedthread” id"closedthread" bacome false without click.
I tried it with: <body class=“closedthread” id"closedthread" onBeforeUnload=“return false;”>, but it works ONLY in IE9.

Most browsers now limit what onbeforeunload can be used for because a lot of sites misuse it. Also some people disable that event in their browser because of the annoying way it is misused.

The only guaranteed way to determine if the web page is still open or not is to use a heartbeat script to track from the server whether the page is still open or not.

http://javascriptexample.net/ajax09.php has an example where you can track how long someone is on the page. To get what you require you’d then need to add a cron job that runs every so often to look to see who has left and to close their chat.

Thank you for the answer, but the chat have that already and check for window open every 1 minute, what I was thinking is about something like this:
<script language=“JavaScript”>
window.onbeforeunload = confirmExit;
function confirmExit()

\\ Here -> body return false;
{
return message to display in dialog box;
}
</script>

With the confirmation alert make the body or the link return false.
As you see I don’t know about javascript :slight_smile: