Last active
June 30, 2020 20:13
-
-
Save Farmatique/b4a0766d56b392e5e670b98b0ddb765d to your computer and use it in GitHub Desktop.
Send data from form iframe using postMessage
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
// somewhere inside iframe on succesfull form submit at https://websitewhereiframelives.com(Pardot) | |
window.parent.postMessage({eventId: 'customEvent', data: {val1: '500'}}, "*"); | |
// inside script on webpage | |
window.addEventListener('message', function(message) { | |
if(message.origin === 'https://websitewhereiframelives.com'){ | |
if(message.data.eventId === 'customEvent'){ | |
console.log(message.data.data.val1); | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment