{"id":16371631,"url":"https://github.com/pbojinov/react-iframe-comm","last_synced_at":"2025-05-08T00:35:24.498Z","repository":{"id":59266215,"uuid":"85131157","full_name":"pbojinov/react-iframe-comm","owner":"pbojinov","description":"React iFrame communication - talk to your iFrames via postMessage","archived":false,"fork":false,"pushed_at":"2022-09-20T13:37:04.000Z","size":963,"stargazers_count":65,"open_issues_count":7,"forks_count":15,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-29T22:32:49.317Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://pbojinov.github.io/react-iframe-comm/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pbojinov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-15T23:29:38.000Z","updated_at":"2024-05-11T06:23:46.000Z","dependencies_parsed_at":"2022-09-21T19:52:17.649Z","dependency_job_id":null,"html_url":"https://github.com/pbojinov/react-iframe-comm","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pbojinov%2Freact-iframe-comm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pbojinov%2Freact-iframe-comm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pbojinov%2Freact-iframe-comm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pbojinov%2Freact-iframe-comm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pbojinov","download_url":"https://codeload.github.com/pbojinov/react-iframe-comm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225106472,"owners_count":17421804,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T03:09:07.534Z","updated_at":"2024-11-18T00:06:50.582Z","avatar_url":"https://github.com/pbojinov.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"React iFrame communication\n============\n\n\u003e A React component for communicating between a parent window and an iframe.\n\n## Demo\n\nLive Demo: [https://pbojinov.github.io/react-iframe-comm/](https://pbojinov.github.io/react-iframe-comm/)\n\nOr locally run:\n\n```\nnpm install\nnpm run storybook\n```\n\nThen open [http://localhost:9009/](http://localhost:9009/) in your browser.\n\n\n## Installation\n\nThe easiest way to use React Iframe Communication is to install it from NPM.\n\n```\nnpm install react-iframe-comm --save\n```\n\nAt this point you can import `react-iframe-comm` in your application as follows:\n\n```javascript\nimport IframeComm from 'react-iframe-comm';\n```\n\n## Usage\n \n\n```javascript\nimport React from \"react\";\nimport IframeComm from \"react-iframe-comm\";\n\nconst Demo = ({}) =\u003e {\n\n    // the html attributes to create the iframe with\n    // make sure you use camelCase attribute names\n    const attributes = {\n        src: \"https://pbojinov.github.io/iframe-communication/iframe.html\",\n        width: \"100%\",\n        height: \"175\",\n        frameBorder: 1, // show frame border just for fun...\n    };\n\n    // the postMessage data you want to send to your iframe\n    // it will be send after the iframe has loaded\n    const postMessageData = \"hello iframe\";\n\n    // parent received a message from iframe\n    const onReceiveMessage = () =\u003e {\n        console.log(\"onReceiveMessage\");\n    };\n\n    // iframe has loaded\n    const onReady = () =\u003e {\n        console.log(\"onReady\");\n    };\n\n    return (\n        \u003cIframeComm\n            attributes={attributes}\n            postMessageData={postMessageData}\n            handleReady={onReady}\n            handleReceiveMessage={onReceiveMessage}\n        /\u003e\n    );\n};\n\nexport default Demo;\n\n```\n\n## Configuration Options\n\n\n```javascript\nIframeComm.propTypes = {\n    /*\n        Iframe Attributes\n        https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#Attributes\n        React Supported Attributes\n        https://facebook.github.io/react/docs/dom-elements.html#all-supported-html-attributes\n        Note: attributes are camelCase, not all lowercase as usually defined.\n    */\n    attributes: PropTypes.shape({\n        allowFullScreen: PropTypes.oneOfType([\n            PropTypes.string,\n            PropTypes.bool\n        ]),\n        frameBorder: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),\n        height: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),\n        name: PropTypes.string,\n        scrolling: PropTypes.string,\n        // https://www.html5rocks.com/en/tutorials/security/sandboxed-iframes/\n        sandbox: PropTypes.string,\n        srcDoc: PropTypes.string,\n        src: PropTypes.string.isRequired,\n        width: PropTypes.oneOfType([PropTypes.string, PropTypes.number])\n    }),\n    \n    // Callback function called when iFrame sends the parent window a message.\n    handleReceiveMessage: PropTypes.func,\n\n    /*    \n        Callback function called when iframe loads. \n        We're simply listening to the iframe's `window.onload`.\n        To ensure communication code in your iframe is totally loaded,\n        you can implement a syn-ack TCP-like handshake using `postMessageData` and `handleReceiveMessage`.\n    */\n    handleReady: PropTypes.func,\n    \n    /*\n        You can pass it anything you want, we'll serialize to a string\n        preferablly use a simple string message or an object.\n        If you use an object, you need to follow the same naming convention\n        in the iframe so you can parse it accordingly.\n     */\n    postMessageData: PropTypes.any.isRequired,\n    \n    /*\n        Enable use of the browser's built-in structured clone algorithm for serialization\n        by settings this to `false`. \n        Default is `true`, using our built in logic for serializing everything to a string.\n    */\n    serializeMessage: PropTypes.bool,\n\n    /*\n        Always provide a specific targetOrigin, not *, if you know where the other window's document should be located. Failing to provide a specific target discloses the data you send to any interested malicious site.\n     */\n    targetOrigin: PropTypes.string\n};\n```\n\n## License\n\nThe MIT License (MIT) - 2017\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpbojinov%2Freact-iframe-comm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpbojinov%2Freact-iframe-comm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpbojinov%2Freact-iframe-comm/lists"}