Skip to content

Instantly share code, notes, and snippets.

@buritica
Last active January 4, 2016 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buritica/8663135 to your computer and use it in GitHub Desktop.
Save buritica/8663135 to your computer and use it in GitHub Desktop.
replace click url in ad iframe
function receiveMessage(e) {
var clickUrl;
if (typeof e.data === 'string' && e.data.indexOf('clickUrl') > -1) {
clickUrl = e.data.split('/')[1];
var links = document.getElementsByTagName('a');
[].forEach.call(links, function(link) {
link.href = link.href.replace('%%CLICK_URL_UNESC%%', clickUrl);
});
}
}
window.addEventListener("message", receiveMessage, '*');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment