Author Topic: logout on window close  (Read 24524 times)

0 Members and 1 Guest are viewing this topic.

florin.serban

  • Jr. Member
  • **
  • Posts: 2
logout on window close
« on: January 27, 2010, 12:57:21 PM »
Hello!
I am using the latest version of Mibew Messenger and I am very pleased with it.
I think you did an awesome job when coding this application.

I am thinking of adding it to my website, but it has a small bug and I need it fixed before I can do that.

Here's what's bugging me.
Each time a visitor closes his page, the chat session remains open and the visitor appears to be "In chat" when he actually isn't there anymore.

I was thinking to atach an onUnload event to the body section in the chat.tpl file, but I am not sure about the code i need to put there so the visitor can be logged out.

I took a look in the js/chat.js file and I have seen two functions "closeThread()" and "onCloseThread()", but I don't have any idea how to use those to accomplish the visitor logout.

Can you please provide some help on the issue?
10x

florin.serban

  • Jr. Member
  • **
  • Posts: 2
Re: logout on window close
« Reply #1 on: January 29, 2010, 07:03:44 AM »
I managed to overcome the issue I had.  ;D
I'm posting the solution here because I've seen others that came across the same problem as I did.

First of all you should download the JQuery library. Once it has downloaded save it in the "webim/js" folder. Rename it to "jquery.js".

Then edit the "webim/styles/default/templates/chat.tpl" (if you are using the default template). In the head section of that file add the following:

Code: [Select]
<script type="text/javascript" language="javascript" src="${webimroot}/js/jquery.js"> </script>

.............................................

<script type="text/javascript">

jQuery(window).unload(function(){
jQuery("a.closethread").trigger("click");
});

</script>

Look at the picture attached to see exactly where to put the line codes above. If you add the code lines different, it's possible for the script added not to work.



And that's it. Now, each time a visitor closes his browser window, he apears as he had logged out.

Note: Because the window.unload() event triggers if the page is refreshed, the visitor is also logged out if he refreshes the page manually. And please excuse my bad english. ;)

pochimen

  • Jr. Member
  • **
  • Posts: 1
Re: logout on window close
« Reply #2 on: February 22, 2010, 09:46:22 PM »
Your solution seems logic, however it does not work for me, i've checked everything (Script, JQuery, etc), no activity when the user click the window close button.

Here I post my solution.

Search the line:
<a class="closethread"  id="close" href="javascript:void(0)" onClick="return false;" title="${msg:chat.window.close_title}"><img src="${tplroot}/images/buttons/close.gif" border="0" alt="${msg:chat.window.close_title}"/></a>

add the id="close" (as seen above)


then add the following script on top

<script type="text/javascript">

window.onbeforeunload = function() {
    document.getElementById('close').click();

</script>

}

Hope this helps!

justin315

  • Jr. Member
  • **
  • Posts: 1
Re: logout on window close
« Reply #3 on: July 19, 2010, 10:19:07 AM »
On my testing,no one is working~

big_harry

  • Jr. Member
  • **
  • Posts: 1
Re: logout on window close
« Reply #4 on: July 25, 2011, 05:57:58 PM »
I had the same problem and I overcame it using pochimen's solution above.  If it didn't work for you then perhaps it was because you copied the script above verbatim which would not work as the closing parenthesis is not within the script.  Try this:

<script type="text/javascript">
window.onbeforeunload = function() {
    document.getElementById('close').click();
}
</script>

von1

  • Jr. Member
  • **
  • Posts: 4
Re: logout on window close
« Reply #5 on: May 03, 2012, 05:06:29 AM »
First of all you should download the JQuery library. Once it has downloaded save it in the "webim/js" folder. Rename it to "jquery.js".

Rather use the included one in 1.6.4

<script type="text/javascript" language="javascript" src="${webimroot}/js/jquery-1.3.2.min.js"></script>


Excellent post.

indedmedia

  • Jr. Member
  • **
  • Posts: 1
Re: logout on window close
« Reply #6 on: May 15, 2012, 11:09:42 AM »
I tried to do all steps here, but to me donĀ“t work :(, can anyone help me?
I need it.

nirpan

  • Full Member
  • ***
  • Posts: 8
Re: logout on window close
« Reply #7 on: November 11, 2013, 01:40:32 PM »
Your solution seems logic, however it does not work for me, i've checked everything (Script, JQuery, etc), no activity when the user click the window close button.

Here I post my solution.

Search the line:
<a class="closethread"  id="close" href="javascript:void(0)" onClick="return false;" title="${msg:chat.window.close_title}"><img src="${tplroot}/images/buttons/close.gif" border="0" alt="${msg:chat.window.close_title}"/></a>

add the id="close" (as seen above)


then add the following script on top

<script type="text/javascript">

window.onbeforeunload = function() {
    document.getElementById('close').click();

</script>

}

Hope this helps!

It did! Thanks for that!