When all your users are offline, or when you’re past working hours, you wouldn’t want to offer a vacant chat window to your website visitor. 

In such situations, you can hide the live chat widget on your website—using visitor APIs.

How to use Freshchat functions

To begin, you must copy the Freshchat script for the widget. You can access the script in your Freshchat Settings page: Settings > Installation Snippet.

Once you paste the script into your website, ensure you call Freshchat functions after the script loads onto your web page. 

These are some of the ways in which you can access Freshchat functions:

window.onload = function(){

//Freshchat functions


If you are using jquery,


//Freshchat functions


Or, if you’re using Onreadystatechange event,

document.onreadystatechange = function(){

if(document.readystate === ‘complete’){

//Freshchat functions



How to hide widget using isUserAvailable() function

The isUserAvailable() function indicates whether users are online or offline. 

  • If the function returns a True value, at least one agent is online. 

  • If the function returns a False value, all agents are offline. 

When the isUserAvailable() function returns False, the hideChat() function is executed as below:

Fig 1: Logic to hide widget

The integrated example below shows how the above function uses the ‘hide chat’ logic and is passed as a parameter to the isUserAvailable() function: 

Fig 2: Demo code to hide widget when all agents are offline