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()`
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()`
Best answer by Aparna-narayanan
hi
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')[0];
head.insertBefore(freshchatScript, head.firstChild);
}
Hope it helps with ur query shared.
Thanks
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.