General > Support

End chat thread on browser close button

(1/2) > >>

nirpan:
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: ---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;
        }

    });
});
--- End code ---

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:

--- Quote from: nirpan on November 21, 2013, 01:34:47 AM ---I [..] was wondering why it was not implemented in the first place?

--- End quote ---

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:
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: ---// Fix Chat Leaves
EventHelper.register(window, 'onbeforeunload', function() {   
    Chat.threadUpdater.closeThread();
});
--- End code ---

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: ---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');
            };
       }
});
});

--- End code ---

Thanks.

faf:
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.


--- Quote from: nirpan on November 21, 2013, 09:42:58 PM ---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.

--- End quote ---

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

nirpan:
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.

Navigation

[0] Message Index

[#] Next page

Go to full version