How to Access iframe from Parent Element – Best Methods? or What's the Proper Way to Access iframe fr

18 Replies, 1368 Views

For accessing iframe from parent element, timing is key. If the iframe hasn't loaded, you'll get nada.

Try this:

```js
document.querySelector('iframe').addEventListener('load', function() {
const innerDoc = this.contentDocument;
// now you can mess with it
});
```

Cross-origin? Nope. Browsers won't let you. `postMessage` or bust.

Messages In This Thread



Users browsing this thread: 1 Guest(s)