Created
September 24, 2014 13:23
-
-
Save Ginden/2d0cd169cb41d887e0a0 to your computer and use it in GitHub Desktop.
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
function clone(obj, callback) { | |
var from = window.location.origin; | |
var wrapper = {'__clone__': true}; | |
wrapper.__data__ = obj; | |
var listener = function(e) { | |
if(e.origin === from && e.data.__clone__) { | |
callback(e.data.__data__); | |
window.removeEventListener('message', listener); | |
} | |
}; | |
window.addEventListener('message', listener); | |
window.postMessage(wrapper, from); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment