I have a large form split into several screens using multiview. On one of those screens is an iframe. The document within the iframe contains some script. I want to execute that script when the cell / iframe loads.
Normally I’d use $$(‘id’).getWindow().function(). This works fine if executed from a button click, for example, but if I want to execute this script when the iframe loads, like so …
$$('id_of_multiview').attachEvent('onViewChange',function(prev,next){
if (next=='cell_containing_iframe') {
$$('id_of_iframe').getWindow().doSomething();
}
});
… nothing happens.
I suspect it’s because ‘onViewChange’ executes before the iframe source is fully loaded and the function it contains is therefore undefined. Other than wrapping it in a timeout is there a way to detect whether the document within the iframe is ready before attempting to execute a script it contains?
You can use
$$('id_of_iframe').attachEvent("onXLE", function(){
this.getWindow().doSomething();
});
onXLE on iframe will fire when document in iframe is loaded.
Doesn’t work, “onXLE” doesn’t fire (nor does “onxle” as these things are sometimes case sensitive).
Hello,
Try to set an event in “on” property:
{
view:"iframe",
on:{
onXLE: function(){
this.getWindow().doSomething();
}
},
...
}
Using ‘on’ the event fires, but it fires when the form is loaded, not the iframe. The iframe is in a cell within a multiview within a form. I need the event to fire when the cell (and the iframe it contains) is displayed.
At the moment in time the form loads the iframe doesn’t contain the data the script it contains acts upon, so firing on form load is no good to me.
For now I’ve used this workaround :-
$$('id_of_multiview').attachEvent('onViewChange',function(prev,next){
if (next=='cell_containing_iframe') {
dhx.delay(someFunction,dhx,[],1000);
}
});
function someFunction(){
$$('id_of_iframe').getWindow().doSomething();
}
My only concern is that by setting a 1 second delay I’m assuming the iframe will always be ready in less than that.
Mark,
we have found an issue with onXLE call for non-visible iframes. I have attached the demo with modified js libs.
demo.zip (205 KB)
Brilliant, works perfectly, thank you as always for your excellent service