0

I have a page with an iFrame on it.

I would like to add the following to the iFrame, with javascript, preferably no jQuery:

onload="resizeIframe(this)"

I do not have to target a specific class, I need the onload to be attached to all iFrames on the page.

Thanks!

EDIT

Right now my iframe looks like this:

<iframe width="100px" height="100px" src="#source">

I need it to look like this after page load:

<iframe width="100px" height="100px" src="#source" onload="resizeIframe(this)">

Hope that is a bit clearer, thanks!

user1525612
  • 1,864
  • 1
  • 21
  • 33
  • Possible duplicate of [Javascript callback when IFRAME is finished loading?](http://stackoverflow.com/questions/164085/javascript-callback-when-iframe-is-finished-loading) – BenM Mar 09 '16 at 15:06

1 Answers1

0
var iframes = document.querySelectorAll('iframe'), i;

function MyFunction(){
console.log("iframe is loaded");
}

for (i = 0; i < iframes.length; ++i) {
  iframes[i].onload = MyFunction;
}
Vladu Ionut
  • 8,075
  • 1
  • 19
  • 30