Skip to content

Instantly share code, notes, and snippets.

@ar5had
Created July 13, 2017 00:45
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 ar5had/5a90e3aa77b1dee7684ed5a044ce3bd1 to your computer and use it in GitHub Desktop.
Save ar5had/5a90e3aa77b1dee7684ed5a044ce3bd1 to your computer and use it in GitHub Desktop.
const { Provider } = ReactRedux;
window.addEventListener("message", e => {
// extentions and other 3rd party scripts talk via postMeessage api(same orgin)
// so it is very important to filter those events
if (e.origin !== window.location.origin || !e.data || e.data.source !== "dialog-message") {
return;
}
// parent and window are same thing if the current page is not in any frame
if (window !== parent) {
parent.postMessage(
{ messageRecieved: true, source: "dialog-message" },
`${window.location.origin}/iframe-testing-ground`
);
}
const state = Object.assign({}, e.data);
window.redux_store.dispatch(window.redux_actions.loadInitialState(state));
});
window.sendState = () => {
window.postMessage(window.redux_store.getState(), `${window.location.origin}`);
};
ReactDOM.render(
<Provider store={window.redux_store}>
<PrintDialog />
</Provider>,
document.getElementById("root")
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment