Created
March 30, 2013 21:02
-
-
Save mattsnider/5278315 to your computer and use it in GitHub Desktop.
Cross-Domain Iframe Receiver Using Hack-Hack
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
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