🏠 back to Observable

IFrame and load event

In 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

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

1 Like

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.

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)