I’m trying to use pop-up forms to collect email addresses before allowing visitors to download files. So far I’ve figured out how to get it to work when there’s only one download on the page, but I’m trying to figure out how to make it work when there are multiple downloads on the page.
Here’s the code I have so far:
var downloadURL = "";
var downloadLinks = document.getElementsByClassName("klaviyo_form_trigger");
for (var i = 0; i < downloadLinks.length; i++) {
downloadLinksoi].addEventListener('click', popUp, false);
}
var popUp = function(e) {
var attribute = this.getAttribute("data-download");
downloadURL = attribute;
window._klOnsite = window._klOnsite || o];
window._klOnsite.openForm('WRbG6e');
e.preventDefault();
};
window.addEventListener("klaviyoForms", function(e) {
if (e.detail.type == 'submit') {
window.location.href=downloadURL;
}
});
This seems to work fine for the first submit, but nothing after.
Any ideas?