Forked from scottmagdalein/clickable-element.html
Last active
December 9, 2019 16:49
-
-
Save tairli/96b0490d71177167a31068f2dd510ec6 to your computer and use it in GitHub Desktop.
Make the Mailchimp Subscriber popup appear on click
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- This is the HTML element that, when clicked, will cause the popup to appear. --> | |
<button id="open-popup">Subscribe to our mailing list</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- this is not necessary if you're only adding popup-on-button functionality to already existing mailchimp popup. | |
Also, mailchimp now uses something like //downloads.mailchimp.com/js/signup-forms/popup/unique-methods/2.0/popup.js | |
with unique-methods in path which uses dojoRequire and dojoDefine instead of require and define | |
--> | |
<script type="text/javascript" src="//s3.amazonaws.com/downloads.mailchimp.com/js/signup-forms/popup/embed.js" data-dojo-config="usePlainJson: true, isDebug: false"></script> | |
<script> | |
function showMailingPopUp() { | |
// If your mailchimp popup tried loading automatically, but had a cookie and did not show | |
// If not done, close button would not work (sorry for jQuery) -- basically removes previous popups | |
$('[id^="PopupSignupForm"]').remove(); | |
// clear 2 cookies on the root path | |
document.cookie = "MCPopupClosed=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/"; | |
document.cookie = "MCPopupSubscribed=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/"; | |
dojoRequire( // using uniq methods, some older code may work with simple require | |
["mojo/signup-forms/Loader"], | |
function(L) { | |
L.start( { | |
"baseUrl":"XXXX.usXX.list-manage.com", | |
"uuid":"YOUR_USERID", | |
"lid":"YOUR_FORM_ID", | |
"uniqueMethods": true // force using uniq methods inside, otherwise will complain about "require/define not defined" | |
}); | |
}); | |
}; | |
document.getElementById("open-popup").onclick = function() {showMailingPopUp()}; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment