How to Call JavaScript Function with a Button Using Popupsmart
Popupsmart allows you to trigger JavaScript functions directly through your popup campaigns. This feature is perfect for integrating web tools, such as opening a chat widget or performing custom actions based on user interaction.
You can execute JavaScript functions using one of the supported formats. Here’s an example on how to integrate a chat widget:

Direct Function Call
1. Define the function on your website as shown in the example.
function openChatWidget() {
console.log("Chat widget opened!");
}2. In your Popupsmart dashboard, set the JavaScript call action to:
openChatWidgetFunction via window Object
1. Define the function globally as shown in the example.
javascript
Copy the code
window.openChatWidget = function() {
console.log("Chat widget opened via window object!");
// Add your chat widget's specific function here
};2. In your Popupsmart dashboard, set the JavaScript call action to:
window.openChatWidget()Supported Formats
Popupsmart supports the following JavaScript call formats:
testFunc: Calls a function by its name.- Example:
function testFunc() { console.log("Function called!"); }
- Example:
window.testFunc: Calls a function defined as part of the globalwindowobject.- Example:
window.testFunc = function() { console.log("Window function called!"); };
- Example:
testFunc(): Calls a parameterless function directly.- Example:
function testFunc() { alert("Hello!"); }
- Example:
window.testFunc(): Calls a parameterless function via the globalwindowobject.- Example:
window.testFunc = function() { alert("Window says hello!"); };
- Example:
testFunc(param1, param2): Calls a function with parameters.- Example:
function testFunc(param1, param2) { console.log(param1, param2); }
- Example:
window.testFunc(param1, param2): Calls a function with parameters through the globalwindowobject.- Example:
window.testFunc = function(param1, param2) { console.log(param1, param2); };
- Example:
Still have questions? Do not hesitate to contact our support team via our AI chatbot.