Created
July 13, 2017 00:45
-
-
Save ar5had/5a90e3aa77b1dee7684ed5a044ce3bd1 to your computer and use it in GitHub Desktop.
Revisions
-
ar5had created this gist
Jul 13, 2017 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ 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") );