Skip to content

Instantly share code, notes, and snippets.

@Farmatique
Last active June 30, 2020 20:13
Show Gist options
  • Save Farmatique/b4a0766d56b392e5e670b98b0ddb765d to your computer and use it in GitHub Desktop.
Save Farmatique/b4a0766d56b392e5e670b98b0ddb765d to your computer and use it in GitHub Desktop.
Send data from form iframe using postMessage
// 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