In my site, I use an iframeA in an iframeB, and, when the iframeA changes it’s content I have to set the src. I can set it only with the onload event, but this called when the site is loaded. I am looking for some event or trigger, that helps me detect the location/src change before it starts loading. I don’t want to wait the whole page load, before the src set. I have no direct access to iframeA (just the script below)
Some code:
var myframe = document.getElementById('frameB').contentWindow.document.getElementById('frameA');
myframe.onload=function (funcname) {...};
What will be changing the source of the iframe? If you have access to that code then you can do whatever is in your
onloadfunction then.If a link has it’s
targetattribute set to the iframe and that is how the source is changing then you can hi-jack the link clicks:Also, just a side-note, you can bind an event handler for the
loadevent in jQuery like this:UPDATE
SITE -> frameB -> frameA
This selects the
#frameBelement (that is in the current top level DOM), gets it’s contents, finds the#frameAelement, and then binds an event handler for theloadevent.Note that this code must be run after
#frameBis loaded with the#frameAelement already present in it’s DOM. Something like this might be a good idea:UPDATE
To hi-jack links in the
#frameBelement:This will find any link in the
#frameBelement that has itstargetattribute set toframeAand add aclickevent handler.And again, this will only work if the
#frameBiframe element has loaded (or atleast gotten to thedocument.readyevent) so you can select it’s elements.