Javascript and working with external scripts
Mailocator allows you to run external scripts including adding custom scripts to windows.
Adding your own javascript
You can add custom code directly to the end of the Mailocator source code on the Setup and Javascript palette. This code will be executed when the Mailocator code is run.
Running the script when the window is displayed
If you wish to call the custom script the moment the campaign is displayed, just add the ML-MAIN
attribute to the onload
container containing the function.
<ml-nain onload="alert('Campaign displayed')"> ... </ml-nain>
Running the script after using the Mailocator action
You can also easily execute custom code using the jsfn
action, for example when submitting a form or creating a cookie consent.
Example of a button that closes the campaign window and then calls the my_function
function:
<button onclick="mailocator.do('close | jsfn:my_function(argument)')">Close</button>
If you want to use a string as a function argument instead of quotes, which cannot be used, use two asterisks, e.g. *
*
text_argument*
*
.