Skip to content

Instantly share code, notes, and snippets.

@mattsnider
Created March 30, 2013 21:02
Show Gist options
  • Save mattsnider/5278315 to your computer and use it in GitHub Desktop.
Save mattsnider/5278315 to your computer and use it in GitHub Desktop.
Cross-Domain Iframe Receiver Using Hack-Hack
var HashHack = {
PREFIX: '#hhMessage=',
aCallbacks: [],
sLastHash: '',
handleInterval: function() {
var sHash = window.location.hash,
sDecodedHash, sMessage, i;
if (sHash !== HashHack.sLastHash) {
// is it valid
sDecodedHash = decodeURIComponent(sHash);
if (0 === sDecodedHash.indexOf(HashHack.PREFIX)) {
sMessage = sDecodedHash.replace(HashHack.PREFIX, '');
HashHack.sLastHash = sHash;
for (i = HashHack.aCallbacks.length - 1; i >=0; i -= 1) {
HashHack.aCallbacks[i]({data: sMessage});
}
}
}
},
init: function() {
setInterval(HashHack.handleInterval, 250);
},
onMessage: function(fnCallback) {
HashHack.aCallbacks.push(fnCallback);
}
};
HashHack.init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment