Forum Moderators: open

Message Too Old, No Replies

Control onload of iframe in fly

How to control a complete load of a Iframe loaded in fly

         

litos334

4:25 pm on Sep 14, 2006 (gmt 0)

10+ Year Member



Hello!

What I intend to do: Click an icon, starting load a Iframe, and only display it when the loading is finished.

A sample:
-------------------------------------------------
<body>
<div id=chat2 onClick="switchtag();" style="display:block;visibility: visible;"><img src="http://www.google.pt/images/logo_sm.gif" border=0></div>
<div align='left' id=ddiv style="display:none;position:absolute;top:10; left:10; width:220;height:370;background:url('notas2.gif') no-repeat;border:0px none">
<iframe scrolling=no frameborder=0 id=ifra style='position:relative;top:20;width:191;height:334;'>
</iframe></div>

<script type="text/javascript" language="javascript">
var tag2='http://www.google.com/search?q=asdf&btnG=Pesquisa+Google&meta=';
var on1=1;
var div = document.getElementById("ddiv");
var ico = document.getElementById("chat2");
//2// document.getElementById('ifra').onload = function() {func2();}

function switchtag(){
if(div.style.display!="none"){div.style.display= "none";ico.style.display="block";}
else {
if(on1==1) {on1=0;
document.getElementById('ifra').onload = function() {func();} //3//
document.getElementById('ifra').src=tag2;
}
else{ div.style.display = "block";ico.style.display="none"; }
}
}

function func(){ div.style.display = "block"; ico.style.display="none"; }

function func2(){div.style.display= "none";ico.style.display="block"; }
</script>
</body>
--------------------------------------------------

The handler .onload in //2//, unfortunately, works as soon as program is load.
But the line //3// do not work, because de Iframe is considered loaded since the program begins.

How can we control a complete load of an Iframe, iniciated by the user (by click a button)?

Thank you and sorry my weak english.

penders

2:31 pm on Sep 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi litos334, (welcome to WebmasterWorld)... I have been experimenting with the same thing. It works OK in Firefox (and so does your code), but in IE6 the onload event on the IFRAME does not fire, after the parent document has already loaded, and there seems to be no-way to reset this?!

I have since found this Microsoft document (admittedly aimed at IE4 and IE5), that states, "You cannot rely on the (onload) property to test whether an IFRAME is loaded.... This behavior is by design.... There is no good way to find out if an IFRAME is loaded from its parent." (By design?! *sigh*)
[support.microsoft.com...]

I have experimented with creating the entire iframe element at runtime, but I can't get an appropriate event to fire in IE6.

litos334

2:13 pm on Sep 19, 2006 (gmt 0)

10+ Year Member



Hi penders,

Thank you for your concern. Meanwhile, I made a search harder in java foruns, and I finally find in TheScripts forum, a good solution that works nice.

-------------------------------------------------------------

<iframe marginwidth=0 marginheight=0 hspace=0 vspace=0 scrolling=no frameborder=0 id=ifra style="position:relative;top:16;left:14;width:191;height:334;border:none;padding:0px;margin:0px;cursor:default;" onload="if (typeof this.loadCount == 'undefined') {this.loadCount = 0;} this.loadCount++; if (this.loadCount > 1) {div.style.display = '';ico.style.display='none';}"></iframe>

------------------------------------------------------------

"This.loadCount" : This option was unknown for me till now.
With this "onload", the first load is discarded, and after that, it works ok.

Thanks again!