In this guide we’ll show you how you can launch and close your Chaty WhatsApp popup from your button using a JavaScript function in a few super simple and quick clicks.
To learn more about how to use the Chaty plug-in click here, and don’t forget to check our entire Chaty knowledgebase to make the most out of it.
You can use this feature to launch or close your WhatsApp popup from anywhere on your website, through a button, and with whatever criteria you want to be met, for example you can only show the widget after other JavaScript commands fire or hide it after a JavaScript command fires.
To launch the Chaty WhatsApp popup with a JavaScript function, add a button on your website.
Then, you need to add this as a link:
javascript:open_chaty_whatsapp_popup();
In the end, it should look something like this on your website:

To close the Chaty widget with a JavaScript function, add a button and add the following JavaScript function:
javascript:close_chaty_whatsapp_popup();
When you’re done, don’t forget to hit ”Save” at the top of the page. That’s it! Easy as 1,2,3 ☺️
Since Elementor’s free version does not provide a built-in option for directly adding JavaScript to buttons, a simple workaround is to add a custom JavaScript snippet to your site. You can add the snippet using any free third-party plugin like WPCode.
Go to Plugins → Add New → search for WPCode and install it.
Copy the script below and paste it into the Footer section of Code Snippets.
<script>
document.addEventListener("DOMContentLoaded", function() {
document.getElementById("openChatyWidget").addEventListener("click", function(event) {
event.preventDefault();
setTimeout(function() {
open_chaty_whatsapp_popup();
}, 100); // Adjust delay if needed
});
});
</script>Edit your Elementor button and enter openWhatsappPopup inside the Button ID field.
Don’t forget to hit the Publish button and that’s it, you can now launch the Chaty WhatsApp popup with your Elementor button!


