question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add `ref` so we can access the `<iframe>` used

See original GitHub issue

When looking at the forwardRef prop I initially expected it to work like React.forwardRef() & the “Forwarding Refs” docs mentions - by being able to access all methods on a <iframe> element (i.e. the HTMLIFrameElement interface) so I could do things like forwardRef.current.contentWindow.location.reload() for instance but was unable to.

It appears that the only methods on forwardRef.current are resize, sendMessage, and moveToAnchor which are exposed in the useImperativeHandle hook here:

https://github.com/davidjbradshaw/iframe-resizer-react/blob/03eea291dbde2ad29c72868c1249f739629a52d9/src/index.jsx#L33-L40

The iframeRef is passed into the <iframe> element here & that’s what I would like to be able to get access to: https://github.com/davidjbradshaw/iframe-resizer-react/blob/03eea291dbde2ad29c72868c1249f739629a52d9/src/index.jsx#L42

However it is not accessible to parent components. Could a ref passed into <IFrameResizer /> get forwarded to the <iframe> element like the “Forwarding Refs” docs outlines? I don’t think any changes to the forwardRef prop or the implementation of the useImperativeHandle hook would be needed. This would be really helpful! Thanks for the great library! Also, here’s an annotated screenshot that might help:

ScreenShot 2020-09-18 at 09 32 00

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:10
  • Comments:6

github_iconTop GitHub Comments

5reactions
monsterkrampecommented, Mar 22, 2021

Up until now, I did not receive any feedback regarding the PR #53 😕 Dunno if and when it will be merged.

0reactions
goncalobocommented, Sep 2, 2021

Bump

Read more comments on GitHub >

github_iconTop Results From Across the Web

get iframe elements in react using ref - Stack Overflow
I got this one : react-dom. development. js:328 Uncaught DOMException: Blocked a frame with origin "file://" from accessing a cross-origin  ...
Read more >
<iframe>: The Inline Frame element - HTML - MDN Web Docs
The HTML element represents a nested browsing context, embedding another HTML page into the current one.
Read more >
Best practices for React iframes - LogRocket Blog
Explore two use cases for React iframes, embedding external content in a web application and isolating certain parts of an app.
Read more >
Accessing an iframe document (contentWindow) - YouTube
In this video we take a look at the contentWindow and contentDocument properties of an embedded iframe - it allows access to the...
Read more >
HTML iframe tag - W3Schools
Definition and Usage ... The <iframe> tag specifies an inline frame. An inline frame is used to embed another document within the current...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found