Author Topic: End chat thread on browser close button  (Read 13761 times)

0 Members and 1 Guest are viewing this topic.

nirpan

  • Full Member
  • ***
  • Posts: 8
End chat thread on browser close button
« on: November 21, 2013, 01:34:47 AM »
Hello Guys,

I have spent quite a bit of my time trying to see if I could find a solution to this but I keep hitting one or the other problem. Basically I want to end the chat thread when the client or operator closes the chat window by pressing the 'X' (close) button of the browser as we noticed too many open threads because they don't realise the difference between the within the chat window and the X of the browser. I tried to use some JS for this and had some success based on the answers I had found in the forum. Here is the code:

Code: [Select]
var clicked = false;

window.onbeforeunload = function(){
    if(!clicked)
        jQuery("#close").trigger('click');
};

jQuery(document).ready(function(){
    jQuery('a').on('click', function(){
        clicked = true;
        if (clicked) {
            window.onbeforeunload = null;
        }

    });
});

This works fine on all browser except IE8 where in IE8, it closes only if the user has not clicked on any link (including the send link). I really am not sure what else to do and was wondering why it was not implemented in the first place?

Thanks.

faf

  • Mibew Staff Member
  • Native
  • *****
  • Posts: 950
    • Mibew Messenger
Re: End chat thread on browser close button
« Reply #1 on: November 21, 2013, 07:29:31 AM »
I [..] was wondering why it was not implemented in the first place?

It was already discussed on this forum not so long ago. Please, read this thread.

As for your code, it looks weird. And it's definitely not the code from the solution you've found.  ;)

At least you could use the selector #close to register a handler for the onclick event only for the right link and not for all links in the document.

nirpan

  • Full Member
  • ***
  • Posts: 8
Re: End chat thread on browser close button
« Reply #2 on: November 21, 2013, 09:42:58 PM »
Hi Faf,

Thank you very much for the reply. I think I was too premature to reply about the solution without fully testing on every browser. I will update my answer to tell about the issue with IE8.

And I should have searched the forum better but my bad. But even after trying the option like setting the chat thread to 5 mins after the browser window is closed, it still shows the chat thread in the visitors window for some reason.

And this quick solution works pretty well on all browser except for IE8 at least, it closes the whole thread every time a link is clicked.
Code: [Select]
// Fix Chat Leaves
EventHelper.register(window, 'onbeforeunload', function() {   
    Chat.threadUpdater.closeThread();
});

You are also right about using the selector #close to register handle for the onClick only for the right selector but because I want the handler to be registered ONLY on the browser window button click, I did that weird way.  I tried something like this but even this did not worked:

Code: [Select]
jQuery(document).ready(function(){
 jQuery('a').on('click', function(){
        clicked = true;
        $this = jQuery(this).attr('id');
        if ($this == 'togglesound') {
            window.onbeforeunload = null;
        } else {
            window.onbeforeunload = function () {
                jQuery("#close").trigger('click');
            };
       }
});
});

Thanks.

faf

  • Mibew Staff Member
  • Native
  • *****
  • Posts: 950
    • Mibew Messenger
Re: End chat thread on browser close button
« Reply #3 on: November 22, 2013, 07:15:26 AM »
So, now you're starting to realize why it's not such an easy task to implement this feature and make it crossbrowser at the same time...  ;)

Maybe this would help.

And I should have searched the forum better but my bad. But even after trying the option like setting the chat thread to 5 mins after the browser window is closed, it still shows the chat thread in the visitors window for some reason.

Actually it should works. But only for the threads that was seen by an operator.

nirpan

  • Full Member
  • ***
  • Posts: 8
Re: End chat thread on browser close button
« Reply #4 on: November 22, 2013, 10:41:04 AM »
Hi Faf,

Indeed it is very very difficult especially when you have to support browsers like IE8 which won't just die already! Thank you for your reply though. I will have a look at the link as well as try out that thread time feature thing and see if it works when the operator sees it.

faf

  • Mibew Staff Member
  • Native
  • *****
  • Posts: 950
    • Mibew Messenger
Re: End chat thread on browser close button
« Reply #5 on: November 22, 2013, 03:12:25 PM »
Indeed it is very very difficult especially when you have to support browsers like IE8 which won't just die already!

You don't say!  :D

I will have a look at the link as well as try out that thread time feature thing and see if it works when the operator sees it.

Ok. And please post here your findings. It can be useful for other people with the same problem.  ;)

nirpan

  • Full Member
  • ***
  • Posts: 8
Re: End chat thread on browser close button
« Reply #6 on: November 25, 2013, 11:07:21 PM »
Hi Faf,

Ha! IE is just so unpredictable in so many sense or maybe I am just shit ;p. So far I have found that closing a chat by closing the chat window works on chrome, firefox and safari when I use this code posted on the other forum:
Code: [Select]
// Fix Chat Leaves
EventHelper.register(window, 'onbeforeunload', function() {   
    Chat.threadUpdater.closeThread();
});

But this cause the chat thread to close every time a link is clicked on IE8. Now I tried adding some JS so that it won't close when a link is clicked (by setting the onbeforeunload to null) but IE8 does the exact opposite of closing the chat thread when the link is clicked; it seems to keep the onbeforeunload value as null.

Now the whole reason to do this was because many operators seem to never click the 'close chat' link within the chat window and just close the browser 'X' button. And they get confused as to why the thread is still there. For now my solution is to simply display the warning popup asking them to use the close chat button in the chat window if they want to end the conversation.

The other issue with the chat thread still being listed on the visitors page, I tested by setting the thread lifetime to 60 seconds and then created a scenario where an client starts a conversation, the operator acknowledges it, after which the client abruptly closes the chat using browser close window. The operator is notified after 60 seconds but the chat thread is still listed in the visitors page until the operator closes it using the close chat. I am not sure if this is how it's supposed to be as I had expected the chat thread to be closed and not appear on the visitors page.

Thanks for your time.

faf

  • Mibew Staff Member
  • Native
  • *****
  • Posts: 950
    • Mibew Messenger
Re: End chat thread on browser close button
« Reply #7 on: November 26, 2013, 07:56:33 AM »
The other issue with the chat thread still being listed on the visitors page, I tested by setting the thread lifetime to 60 seconds and then created a scenario where an client starts a conversation, the operator acknowledges it, after which the client abruptly closes the chat using browser close window. The operator is notified after 60 seconds but the chat thread is still listed in the visitors page until the operator closes it using the close chat. I am not sure if this is how it's supposed to be as I had expected the chat thread to be closed and not appear on the visitors page.

Actually, yes, it's supposed to be so. Mibew Messenger 1.6.x closes only old threads that was seen by an operator. It's the limitation of the application design.