All the information you need in one place

How to Open a Popup on Custom JS Function

You can use Nelio Popups to show a popup based on the result of executing a custom JavaScript function of your choice. This can be helpful when displaying different popups depending on the result of a function from your own codebase.

In this article, you’ll learn how to open popups according to a JavaScript function.

Using Custom JS Function Condition

When you are ready to use the Custom JS Function condition, follow these steps:

  1. Go to Nelio Popups » All Popups and edit the one you want.
  2. In the editor sidebar, go to the Settings panel, and open the Conditions tab.
  3. Add or modify a condition by selecting ‘Custom JS function’.
Popup with a Custom JS function condition set.
Popup with a Custom JS function condition set.

Then you need to type the name of your JavaScript function (without parenthesis).

Then, Nelio Popups will try to open the popup according to its configuration (locations and triggers). At that time, Nelio Popups will check if there is a JavaScript function with the name you set in the settings. If the function exists, Nelio Popups will execute it and depending on the result of said execution, the popup will open or not.

Nelio Popups will only open the popup if the result of the execution of your JavaScript function is true. In addition to it, note that the JavaScript function must be accessible in the public scope in order to be executed.