JavaScript API

Start and Close chat events

To execute own javascript code when chat is started or closed, you can customize chat button integration code (with bold is marked our customization, the rest of the code is standard chat button integration code): <script type="text/javascript"> (function(d, src, c) { var t=d.scripts[d.scripts.length - 1],s=d.createElement('script');s.id='la_x2s6df8d';s.async=true;s.src=src;s.onload=s.onreadystatechange=function(){var rs=this.readyState;if(rs&&(rs!='complete')&&(rs!='loaded')){return;}c(...

Set visitor specific values with javascript

These functions are useful when you already have some info about the visitor who is for example logged in to your e-shop or intranet and you want to set their user details (i.e. name, email, phone number or custom field values). If you integrate this javascript call by a simple change in any widget integration code, you will be able to see the visitor's name in the list of online visitors in Chats > Chats overview and when they start a chat or open LiveAgent contact form their details will be...

Button.onOnline(), Button.onOffline()

Sometimes you might need to execute some custom javascript code just after a chat button (https://www.liveagent.com/features/real-time-chat/) is loaded depending on whether the button is online or offline. For this situation, we added these 2 callback functions in version 4.17.3 which you can override and specify your own code that will execute. Button.onOnline() Button.onOffline() **Example use** For example, let's say that we want to display chat button if there are available ag...

Detect state of widget on page

If you need to check on a page where is included any LiveAgent widget if the widget is opened or not, you can use following javascript function: LiveAgent.instance.hasOpenedWidget(); A function returns true if any widget on the page is opened (e.g. from chat button included in your page was started chat), otherwise returns false. 1. Example (widget closed) 2. Example - widget opened:
×