Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 955
  • Last Modified:

iframe on webpage interfering with documentcomplete event

From what I understand, DocumentComplete fires when a page is done loading. However, if there is a frame on the page, it will ALSO fire when that frame is done loading. So if the main page hasn't finished loading yet but a frame has, DocumentComplete fires telling the code to continue on because the page is done loading and I'll end up getting errors.

The page in question has a single <iframe>. It looks like documentcomplete is firing when this iframe is done loading. There are no other <frame> tags on the page. Is there a way for me to just have documentcomplete fire when the main page is loading? Or some other solution that will prevent this premature firing or wait for 2 documentcompletes to fire.
0
JohnDoeSr
Asked:
JohnDoeSr
  • 3
  • 2
1 Solution
 
paulgrunnerCommented:
You can use a blocking while loop:

Dim objHTML as HTMLDocument
Set objHTML = ObjIE.Document


'This is the while loop. You can use DoEvents to allow processing windows messages:
While objHTML.readystate <> READYSTATE_COMPLETE
   DoEvents
Wend

0
 
nffvrxqgrcfqvvcCommented:
How To Determine When a Page Is Done Loading in WebBrowser Control
http://support.microsoft.com/kb/q180366/
0
 
JohnDoeSrAuthor Commented:
Thanks for the replies. paulgrunner, is there any advantage to using objhtml.readystate versus explorer.readystate or webbrowser.readystate? I've already used the previous 2 in do loops and as soon as the first frame on the page is done loading, the documentcomplete event fires and readystate = readystate_complete even though the rest of the page isn't yet done.

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
paulgrunnerCommented:
Use the following code:

    Set objIE = New InternetExplorer
    objIE.Visible = True
    objIE.navigate "http://www.yourpage.com"
    While objIE.readyState <> READYSTATE_COMPLETE
        DoEvents
    Wend
    Dim objHTML As HTMLDocument
    Set objHTML = objIE.document
    While objHTML.readyState <> "complete"
        DoEvents
    Wend

Note that the first loop makes sure we can set the document object, while the second makes sure it's done.
Use this instead of the documentComplete event.
0
 
JohnDoeSrAuthor Commented:
Hi Paul. In General Declarations i had to insert

Public objIE As SHDocVw.InternetExplorer

to get the IE aspect working right.

In Sub Form (load) I inserted the code you suggested above.
When hitting Play I get a compile error 'User-Defined type not defined error on the Dim objHTML as HTMLDocument line. If I omit from that line down then IE will launch successfully.

In the project I have Microsoft Internet Controls (shdocvw.dll) component added along with References to Microsoft Internet Controls (shdocvw.oca & shdocvw.dll), OLE Automation and runtime object produces/ vb for applications & vb objects and procedures.
0
 
paulgrunnerCommented:
Add reference also to Microsoft HTML Object Library
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now