I have a modal dialog that is opened when user clicks in a button. It must be dynamic. It has a lot of images from external sources, e.g. <img src="http://example.com/image.jpg">
. After this modal is opened I want to sum the height of all images loaded. So I'm calling imageCalculation()
in onShow
<p:dialog
id="myDialog"
widgetVar="myDialogWV"
modal="true"
dynamic="true"
onShow="imageCalculation(); ">
<ui:include src="/somePage.xhtml" />
</p:dialog>
<script type="text/javascript">
function imageCalculation(){
var total = 0;
$.each($('#form\\:myDialog').find('img'), function(k,v){
total += v.naturalHeight;
});
alert(total);
}
</script>
The problem is that at the moment imageCalculation()
is called, the images haven't been loaded from external sources yet, and naturalHeight
is still 0.
Is there a way to run a javascript after all the dialog content is completely loaded?
EDIT: The content from somePage.xhtml
is populated by a p:dataGrid
that gets HTML code pieces from DB. Some of these codes are <img
... So theoretically I can't change them
Thanks