# IFrame and load event

**URL:** <https://talk.observablehq.com/t/iframe-and-load-event/3871>\
**Category:** Uncategorized\
**Created:** [September 12, 2020, 8:13pm UTC](https://talk.observablehq.com/t/iframe-and-load-event/3871 "2020-09-12T20:13:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![severo](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/severo/32/786_2.png) [@severo](https://talk.observablehq.com/u/severo)\
**Post date:** [September 12, 2020, 8:13pm UTC](https://talk.observablehq.com/t/iframe-and-load-event/3871/1 "2020-09-12T20:13:51Z")

</div>

In [https://observablehq.com/@mbostock/file-input](https://observablehq.com/@mbostock/file-input), an image(HTMLImageElement) is prepared in a Promise and resolved when it has loaded, so that other cells then directly have access to the loaded image.

I expected to be able to do the same with an iframe, since it also has a load event. But it does not work the same way. I obtained something nearly satisfying but not exactly: [https://observablehq.com/@severo/iframe-and-load-event](https://observablehq.com/@severo/iframe-and-load-event)

If you have comments or solutions, I would be happy to learn!

---

<div class="post-metadata">

**Author:** ![mootari](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mootari/32/581_2.png) [@mootari](https://talk.observablehq.com/u/mootari)\
**Post date:** [September 13, 2020, 9:23am UTC](https://talk.observablehq.com/t/iframe-and-load-event/3871/2 "2020-09-13T09:23:20Z")

</div>

Have you considered using viewof? That way you could add the iframe to the DOM (within the cell wrapper) and still return a promise as value. It would also allow you to wrap iframe modifications in a custom API.

---

<div class="post-metadata">

**Author:** ![severo](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/severo/32/786_2.png) [@severo](https://talk.observablehq.com/u/severo)\
**Post date:** [September 13, 2020, 9:46am UTC](https://talk.observablehq.com/t/iframe-and-load-event/3871/3 "2020-09-13T09:46:38Z")

</div>

Excellent idea! I updated the notebook with an implementation, it’s much better:

- it’s easier to embed in a function (no need to manage a Generator)
- it’s _observablic_ (as pythonic is for python)
