Created
December 27, 2016 09:33
-
-
Save shulard/b55e3893e2c1b8e1efe030869e614102 to your computer and use it in GitHub Desktop.
Utilisation de l'API window.postMessage pour communiquer avec une iFrame...
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
var callback = function(event) { | |
//Protection contre le hack, on n'autorise que les event venant de la frame cible | |
var origin = event.origin || event.originalEvent.origin; | |
if (origin !== 'http://domaine.de.ton.iframe.com') { | |
return; | |
} | |
if (event.data === 'tonmessage') { | |
//Ici tu peux déclencher ton tracker | |
} | |
} | |
//Compatibilité avec IE8 / IE9 | |
if (window.attachEvent !== undefined) { | |
window.attachEvent('message', callback); | |
} else { | |
window.addEventListener('message', callback); | |
} |
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
if( window.top.postMessage !== undefined ) { | |
window.top.postMessage('tonmessage', 'http://domaine.de.ta.page.hote.com'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment