Last active
January 24, 2018 17:00
-
-
Save ChrisLTD/6aeb648622bec3dd5468985b527926ae to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Creates iframe to submit lead data to pardot | |
// @paramList should be in the format param1=something¶m2=somethingelse | |
function submitPardotLead(formHandlerUrl = '//localhost/no-valid-form-handler-url', | |
paramList = 'noparams=provided', | |
callbackFn = function() {}) { | |
// build URL | |
var srcUrl = formHandlerUrl + '?' + paramList; | |
// create iframe el | |
const bodyEl = document.querySelector('body'); | |
var iframeEl = document.createElement('iframe'); | |
iframeEl.setAttribute('src', srcUrl); | |
iframeEl.setAttribute('class', 'pardot-form-handler'); | |
iframeEl.setAttribute('width', '0'); | |
iframeEl.setAttribute('height', '0'); | |
iframeEl.setAttribute('style', 'width: 0px; height: 0px; display: none !important;'); | |
// once the iframe is loaded, fire the callback | |
iframeEl.addEventListener('load', function(){ | |
callbackFn(); | |
}); | |
// appending it with the proper src tag is the same as submitting the form | |
bodyEl.appendChild(iframeEl); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment