IFrame onLoad event with React
See original GitHub issueI have the following iframe element rendered in one of my React components:
<iframe ref="iframe" src={this.props.url} width="100%" height="100%" frameBorder="0"></iframe>
I have tried adding onLoad event as well as attaching onload directly to DOM like so:
this.refs.iframe.getDOMNode().setAttribute('onload', this.getUrl);
Where getUrl is the function of my React component:
getUrl: function() {
var path = this.refs.iframe.getDOMNode().contentWindow.location.pathname;
console.log(path);
},
Except that won’t work. if I set attribute to "getUrl()" - IFrame will look for that function in the global scope, if i set it to the above, IFrame won’t recognize React component’s this.getUrl function.
In Short: I want to notify the React component whenever a URL changes inside the iframe.
Issue Analytics
- State:
- Created 9 years ago
- Reactions:4
- Comments:15 (3 by maintainers)
Top Results From Across the Web
Handling iframe loading in React - Medium
This loads an external google form iframe. First, we'll add a state of loading to the component that starts out as true. Then,...
Read more >How to wait until React in an iframe rendered it's content
Using console.log to log the body of the iframe in the onload function displays the full body and all widgets of the React...
Read more >How to detect if an iFrame is fully loaded in React using a ...
Let's create a custom React hook written in TypeScript that will listen for an iFrame 'load' event and return true or false depending...
Read more >Best practices for React iframes - LogRocket Blog
In React, developers use iframes to create either a sandboxed component or an application that is isolated from its parent component. In an ......
Read more >iFrame onLoad - CodeSandbox
TemplateReact Typescript; Environmentcreate-react-app. Files. public. src. App.tsx. index.tsx. styles.css. package.json. tsconfig.json. Dependencies.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
IFrame onload event is fired in Firefox but not in Chrome. I am using Firefox v41 and Chrome v46 and react v0.13.3. Below is the jsx
Should I consider upgrading to react 0.14 for this to work?
@jketcham Yes! Want to send a pull request? I think we’re missing onError and onLoad which can probably both go in a new subsection called “Generic Events” (no special properties). Also onReset should be listed under Form Events.