0

I want to fire a function on load of my iframes, the problem being that some are generated dynamically, which dont fire the .load() event, I've tried:

$('.upload-target').on('load',uploadDone)

function uploadDone(){
    alert('ewfweewf');
}

but no luck.. how can I trigger a function on load of a dynamically generated iframe?

rpsep2
  • 3,061
  • 10
  • 39
  • 52
  • First, you would need to use the proper delegation syntax of .on. However, i'm not entirely sure whether or not the load event propagates in all browsers.(which would make what you are trying to do nearly impossible without going an entirely different route) – Kevin B Feb 19 '13 at 22:05
  • There is nothing wrong with how he's used `.on()`. An example straight from jQuery's own docs: `function notify() { alert("clicked"); } $("button").on("click", notify);` – idrumgood Feb 19 '13 at 22:06
  • @idrumgood Yes, but that syntax won't delegate the event to dynamic elements. He's missing the delegate target and context. – Kevin B Feb 19 '13 at 22:07
  • See http://stackoverflow.com/questions/4548984/detect-if-the-iframe-content-has-loaded-successfully – idrumgood Feb 19 '13 at 22:08

3 Answers3

0

Try this:

$('.upload-target').load(function(){
    alert('ewfweewf');
});
NT3RP
  • 15,262
  • 9
  • 61
  • 97
starowere
  • 113
  • 4
0

As you can see at this fiddle, http://jsfiddle.net/Uj3bH/ the load event does not propagate, therefore you will not be able to use event delegation to bind to the load event of the iframe. Instead, bind the event when you create the dynamic iframe.

$(iframehtmlstring).appendTo("body").on("load",function(){
    console.log("worky")
});
Kevin B
  • 94,570
  • 16
  • 163
  • 180
0

I would say the load does not propagate because of same-origin-policy An attacker could misuse loading-time to gain additional information. For example a loading-time could take longer if logged in.

If not.. well, then I've found a security-issue ;)

El Hocko
  • 2,581
  • 1
  • 13
  • 22