Jump to content

How to detect close tab in firefox and IE7?


Festy

Recommended Posts

Hello folks,

 

My question is same as the title of this thread. "How do I detect closure of a tab in firefox and new versions of IE? I need this is to know because I want to 'run some scripts/call a php function' when a tab is closed. Please don't suggest me 'onunload' because it doesn't work as when you refresh your browser, that event is triggered.

 

Can anyone help?

Can you not use the javascript in the header like the post above but make a call to a php script rather then giving the user a yes/no exit box when they close the tab?

 

<script language="JavaScript">
  window.onbeforeunload = confirmExit;
  function confirmExit()
  {
    <?php insert code here ?>
  }
</script>

 

I havent tested it but it should just process the php on any closure.

Can you not use the javascript in the header like the post above but make a call to a php script rather then giving the user a yes/no exit box when they close the tab?

 

<script language="JavaScript">
  window.onbeforeunload = confirmExit;
  function confirmExit()
  {
    <?php insert code here ?>
  }
</script>

 

I havent tested it but it should just process the php on any closure.

 

As I said, even if that work, the onunload will get called even when you navigate to different page on same site or when you refresh the same page. So, if I call a logout function on 'onUnload', the user will be logged out as soon as he leaves the page or refresh it. (which I don't want)

To cut a long topic short, I dont think there is any way to diff between a user navigating away from a page and a user closing his or her tab.

The best your going to get is as per the other guys post about sessions but these will only close when the browser is closed.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.