addEventListener to IFRAME



Next challenge.. :-)

How to execute a function on 'load' of (dynamically created) iframe..
E.g: alert the title of loaded document....



Tried this:

var frms =
document.getElementById('container').getElementsByTagName('iframe');
for(var i=0; i<frms.length; i++) {
frms[i].addEventListener("load", function() {
alert(frms[i].contentWindow.content.title);}, false);
}

This doesn't work.... :-(

Next 'solution' only alerts initial loaded page title:

var iFrames =
top.document.getElementById('container').getElementsByTagName('iframe');
for(var i=0; i<iFrames.length; i++) {
(function(monkey) {
iFrames[i].addEventListener('load', function(e) {
alert(this.src);
}, false);
})(iFrames);
}


Hope someone can help me out :-))))


Thanx in advance anyway..
Marco


.



Relevant Pages

  • Re: Cross domain iframe access
    ... value of the - location - property of an IFRAME that contained a page ... babyhood and "throw" even for programmers was first associated with ... sense as one doesn't break code execution unless it is indeed ...
    (comp.lang.javascript)
  • Re: method execution problem
    ... > In the Parent.html page there is a iframe. ... > parentMethod is in the Main.js file and the js file is included in the ... > if I uncomment the alert statement in the parentMethod, method executes ...
    (microsoft.public.scripting.jscript)
  • Re: General DHTML question about ID
    ... alert -> ... so what i want to say is, i can only set the src property of an iframe ... without even the implied warranty of merchantability ...
    (microsoft.public.scripting.jscript)
  • IFrame.onload, IE and Remote Scripting
    ... in the game and XMLHttpRequest was already out there by the time I got ... handler in their server response)...and there I am creating the iframe ... I then load cross-domain requests by setting the src attribute of the ... In opera and FF, I get my little alert box, so I'm good to go ...
    (comp.lang.javascript)

Loading