1

This question has been asked before on other forums but dont see to be able to find an answer the works, so asking again incase anyone can help.

I have the facebook chat plugin on my website www.tiqy.com, which works fine with the following code. The part that doesnt work is "FB.Event.subscribe('customerchat.dialogHide',FB.CustomerChat.hide());". When someone closes the chat I want the whole chat icon to disappear. I have read and tried to follow the facebook documentation, but it doesnt seem to work.

 window.fbAsyncInit = function () {
            FB.init({
                status: false,
                cookie: false,
                xfbml: false,
                version: 'v6.0'
            });
            FB.Event.subscribe('customerchat.dialogHide',
                FB.CustomerChat.hide());

        };

        (function (d, s, id) {
            var js, fjs = d.getElementsByTagName(s)[0];
            if (d.getElementById(id)) return;
            js = d.createElement(s); js.id = id;
            js.src = 'https://connect.facebook.net/en_US/sdk/xfbml.customerchat.js';
            fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));</script>
  • I don’t think the syntax they provide in the docs is correct. `FB.Event.subscribe('customerchat.dialogHide', callback());` – this should not be `callback()`, because that would call the function right then and there; but only `callback` instead, to pass the _reference_ to the function. So try `FB.Event.subscribe('customerchat.dialogHide', FB.CustomerChat.hide);` – CBroe Mar 02 '20 at 08:30
  • Thank you so much. The code now works. I should have realised that. I really appreciate it. I dont know how to mark your comment as the answer, let me know and i will do that. – David Brosnan Mar 03 '20 at 22:20
  • I added an answer, feel free to mark it as the correct solution. – CBroe Mar 04 '20 at 07:24

1 Answers1

1
FB.Event.subscribe('customerchat.dialogHide',
  FB.CustomerChat.hide());
};

The syntax of the example they provide in the docs is not correct.

FB.Event.subscribe('customerchat.dialogHide', callback()); – this should not be callback(), because that would call the function right then and there; but only callback instead, to pass the reference to the function.

So try FB.Event.subscribe('customerchat.dialogHide', FB.CustomerChat.hide);

CBroe
  • 91,630
  • 14
  • 92
  • 150