Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

iframe onload not working 1

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
I am trying to hide an iframe until its contents has loaded.

I'm doing the following...

Code:
    <div id="grasp_doc" style="display:none;">
    <iframe style="width:900px; height:500px; border:1px solid #233e97; margin-bottom:5px;" frameborder="0" src="<tmpl_var name='doc'>" onload="show_doc();"></iframe>             
    <form action = "<tmpl_var name='url_to_cgi'>/grasp_sys.pl" method="post" onsubmit="return check_read(this);">
        <fieldset id="declare">
        <legend>Declaration (tick box to agree)</legend>
            <label for="declaration">I confirm I have fully read the above 'grasp' document.</label>
            <input type="checkbox" name="declaration" id="declaration" value="1" />                         
        </fieldset>  
        <input type="submit" name="submit" id="submit" value="Submit 'read' confirmation" />     
    </form>  
    </div>
    <h2 id="grasp_msg">Please Wait&hellip; document is loading.</h2>

and
Code:
    function show_doc (){
        document.getElementById('grasp_doc').style.display='block';
        document.getElementById('grasp_msg').style.display='none';
    }

Only the iframe is never displayed, i even added an alert in the show_doc code, so I have to conclued that an iframe onload event doesn't exist?

Am I doing something wrong? how else can i detect an iframe has loaded its contents?

NB. loading document is a PDF.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
update-> interestingly it works at home on my win7 machine but not at work with my XP machine.

Both IE8.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
Hi

1DMF said:
I have to conclued that an iframe onload event doesn't exist?
Correct.
HTML 4.01 said:
[tt]onload[/tt] = script [CT]
The [tt]onload[/tt] event occurs when the user agent finishes loading a window or all frames within a FRAMESET. This attribute may be used with BODY and FRAMESET elements.
( HTML 4.01 | Scripts | Designing documents for user agents that support scripting | Intrinsic events | [tt]onload[/tt] )

The ugliest part is, that the [tt]iframe[/tt] element is a [tt]Window[/tt] object in JavaScript, so it has [tt]onload[/tt] event. But I can not make it work. :-(

I found this workaround to mostly work with Gecko ( FireFox, SeaMonkey, Epiphany, Galeon yes, but Phoenix no ), Presto ( Opera ), WebKit ( Midori yes, but Arora no ), KHTML ( Konqueror ) :
HTML:
[b]<iframe[/b] [maroon]name[/maroon][teal]=[/teal][green][i]"inner"[/i][/green] [maroon]src[/maroon][teal]=[/teal][green][i]"whatever"[/i][/green][b]></iframe>[/b]
JavaScript:
[b]var[/b] time[teal]=[/teal][COLOR=darkgoldenrod]setInterval[/color][teal]([/teal][b]function[/b][teal]()[/teal][teal]{[/teal] [b]if[/b] [teal]([/teal]inner[teal].[/teal]location[teal].[/teal]href[teal]!=[/teal][green][i]'about:blank'[/i][/green][teal])[/teal] [teal]{[/teal] [COLOR=darkgoldenrod]clearInterval[/color][teal]([/teal]time[teal]);[/teal] [COLOR=darkgoldenrod]alert[/color][teal]([/teal][green][i]'Content Arrived'[/i][/green][teal])[/teal] [teal]}[/teal] [teal]}[/teal][teal],[/teal][purple]500[/purple][teal])[/teal]
Not tried with PDF, as I have no plugin installed for that.

Feherke.
 
Why does it work on my Win7 machine?

I've just tried with FireFox (at work) and it doesn't work either.

Is this an OS thing rather than a browser thing?

I've thought about loading a dummy page first with my please wait message.

I'll have a quick play and let you know how I get on.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
it's very odd that Win7 works with IE8 but XP and IE8 doesn't.

Anyway, I cracked it by simply having a dummy HTML page with my wait message which is the default src to the iframe.

I then put an onload on the main document body to call a script which changes the src of the iframe to the required document.

Luckily the old page is still visible while the new src loads and only changes once the new src has loaded.

So thanks for the nudge in the right direction Feherke.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top