Hello, I want to trigger a fuction when a user close the Chatbot window. How can I get the event “close window” in js ?
Thanks
Hello, I want to trigger a fuction when a user close the Chatbot window. How can I get the event “close window” in js ?
Thanks
Sure, here is the code for creating the close window event in the Custom JS:
util.addListener(".es-window-close-button", "click", () => {
// Your code goes here
});
If you need further help with the widget customization, just describe your idea. Our devs will gladly help you with it ![]()
Thanks a lot, it works well !
You’re always welcome!
By the way, we’d like to invite you to participate in our September Contest, where you can win a 6-month extension for your subscription - September Contest: Best AI Feature Ideas Win 6 Months FREE!![]()
Check the details and join in ![]()
I have an other question about it, I’d like to catch the escape event too when you press “esc” on the keyboard ?
You’d like to close the chat window when pressing “Esc”, am I right?
I wanted to catch the escape event to close an overlay. I found a way to do it:
document.addEventListener("keydown", (e) => {
Ah, I see! Glad to see you’ve managed to achieve this, and thanks for sharing the solution here ![]()
I did it, it used to work but now it does not work anymore.
util.addListener(“.es-window-close-button”, “click”, () => {overlayDiv.style.display = “none”;console.log(‘close window.’);});
Hi there, @Frederic_Revellat ![]()
Apologies for the inconvenience!
After a recent update, the class of the close button element was changed from .es-window-close-button to .es-header-button-close.
I’ve updated the script in your widget. Here is how it looks now:
util.addListener(".es-header-button-close", "click", () => {
overlayDiv.style.display = "none";
console.log('close window.');
});
Please check it out and let me know how it’s working now ![]()
Sorry it does not work still, I don’t even get any log on the console
fyi this code still works well:
document.addEventListener("keydown", (e) => {
if (e.key === "Escape") {
overlayDiv.style.display = "none";
}
});
We’ve reviewed the code with the devs. The thing is that the closing event occurs before the click registration event . Please try to use this code instead ![]()
document.addEventListener('click', (e) => {
if (e.target.closest('.es-header-button-close[aria-label="Close"]')) {
overlayDiv.style.display = "none";
console.log('close window.');
}
});
Perfect it works well ! thank you so much for your reactivity, 5-star support !
Amazing, thanks a ton for your warm feedback!
If anything else comes up, we’ll be happy to assist ![]()