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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.