Skip to main content

According to the documentation (https://developers.freshchat.com/web-sdk/v2/#messenger-api) we can destroy the Freshchat via `window.fcWidget.destroy()` call.

But how to re-initialize the Freshchat again?
It doesn't work via `window.fcWidget.init()`

hi ​@evgen12 

 

To initialize widget post destroy, we can have the initialization inside a method like this and call the function in the call back of the widget:destroyed function.

 



window.fcWidget.on("widget:destroyed", function() {
console.log('After widget destroyed');
initWidget();
// Do some clean-up here
});



function initWidget(){
window.fcWidgetMessengerConfig = {
// add your config here
}
var freshchatScript = document.createElement('script');
freshchatScript.src = '//fw-cdn/********/****.js'; // add the unified js here
freshchatScript.setAttribute('chat', 'true');
//freshchatScript.setAttribute('widgetId', 'widgetUUID');
freshchatScript.id = 'freshchatScript'; // Assign an id to the script
freshchatScript.onload = () => {
window.fwcrm.on('widget:loaded',function(){
// Add your custom code here
});
}
// Append the script to the head of the document
var head = document.head || document.getElementsByTagName('head')e0];
head.insertBefore(freshchatScript, head.firstChild);
}

Hope it helps with ur query shared.

 

Thanks