Skip to content

Instantly share code, notes, and snippets.

@Ginden
Created September 24, 2014 13:23
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 Ginden/2d0cd169cb41d887e0a0 to your computer and use it in GitHub Desktop.
Save Ginden/2d0cd169cb41d887e0a0 to your computer and use it in GitHub Desktop.
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