Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. axWebBrowser DocumentComplete

axWebBrowser DocumentComplete

Scheduled Pinned Locked Moved C#
helpquestion
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jasper4C
    wrote on last edited by
    #1

    Hi ppl! In my program I need to catch the axWebBrowser1 'DocumentComplete' event. But I find out that this event happens more than 1 times !!!?? At some pages it even happens 7 or 8 times !! Why is this ??? And how I can tell if this is very last chance when it happens (document completly loaded) or there's will be more 'DocumentComplete' events ??? Please help - this is extremly important to me "I have not failed. I've just found 10,000 ways that won't work." - Thomas Alva Edison (1847-1931)

    J 1 Reply Last reply
    0
    • J Jasper4C

      Hi ppl! In my program I need to catch the axWebBrowser1 'DocumentComplete' event. But I find out that this event happens more than 1 times !!!?? At some pages it even happens 7 or 8 times !! Why is this ??? And how I can tell if this is very last chance when it happens (document completly loaded) or there's will be more 'DocumentComplete' events ??? Please help - this is extremly important to me "I have not failed. I've just found 10,000 ways that won't work." - Thomas Alva Edison (1847-1931)

      J Offline
      J Offline
      John Fisher
      wrote on last edited by
      #2

      Hi. I believe that this link[^] adequately addresses your issue. (Unless you can't figure out how to do the pDisp comparison in C#.) John
      "You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.

      J 1 Reply Last reply
      0
      • J John Fisher

        Hi. I believe that this link[^] adequately addresses your issue. (Unless you can't figure out how to do the pDisp comparison in C#.) John
        "You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.

        J Offline
        J Offline
        Jasper4C
        wrote on last edited by
        #3

        Hi man !! Thanks for the answer - very helpfull. But you see - I'm still having problems with determinate when exactly web page is loaded :( I'm trying to receive IHTMLCollection from axWebBrowser.Document from some news web site (the url is http://www.lenta.ru) For the very bad luck I choosed this site to test my collection with and I still receive a weird result :(( Sometimes the size of collection is 2069 elements and sometimes (I just hit refresh button I receive collection of 2065 (!) elements and so on... I don't know what to do :( Seems to me I can't really lock on the page and some elements are missing (?) sometimes ??? Any sugestions ??? "I have not failed. I've just found 10,000 ways that won't work." - Thomas Alva Edison (1847-1931)

        J 1 Reply Last reply
        0
        • J Jasper4C

          Hi man !! Thanks for the answer - very helpfull. But you see - I'm still having problems with determinate when exactly web page is loaded :( I'm trying to receive IHTMLCollection from axWebBrowser.Document from some news web site (the url is http://www.lenta.ru) For the very bad luck I choosed this site to test my collection with and I still receive a weird result :(( Sometimes the size of collection is 2069 elements and sometimes (I just hit refresh button I receive collection of 2065 (!) elements and so on... I don't know what to do :( Seems to me I can't really lock on the page and some elements are missing (?) sometimes ??? Any sugestions ??? "I have not failed. I've just found 10,000 ways that won't work." - Thomas Alva Edison (1847-1931)

          J Offline
          J Offline
          John Fisher
          wrote on last edited by
          #4

          I'm having trouble understanding what your code is really doing. Where did this collection with 2056 elements come from? The axWebBrowser.Document itself shouldn't be changing, but its content will be. John
          "You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.

          J 1 Reply Last reply
          0
          • J John Fisher

            I'm having trouble understanding what your code is really doing. Where did this collection with 2056 elements come from? The axWebBrowser.Document itself shouldn't be changing, but its content will be. John
            "You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.

            J Offline
            J Offline
            Jasper4C
            wrote on last edited by
            #5

            Here you go the full (almost) source code //Web browser settings this.webBrowser.AddressBar = false; this.webBrowser.Dock = DockStyle.Fill; this.webBrowser.FullScreen = true; this.webBrowser.MenuBar = false; this.webBrowser.Offline = false; this.webBrowser.RegisterAsBrowser = true; this.webBrowser.RegisterAsDropTarget = false; this.webBrowser.Silent = true; this.webBrowser.StatusBar = false; this.webBrowser.TheaterMode = true; . . . private void webBrowser_DocumentComplete (object sender,AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e) { //Test counter - to see how many times this event rised ++this.tempCounter; if ( sender.Equals((object)this.webBrowser) && this.webBrowser.ReadyState.Equals(SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)) { MessageBox.Show ("Done loading\n\nLoaded " + this.tempCounter.ToString() +" times", "Document loaded"); //Receive global Document htmlDocGlobal = (mshtml.IHTMLDocument2) webBrowser.Document; if (clickEvent == null) { //Hook the event if not hooked till now clickEvent = (mshtml.HTMLDocumentEvents2_Event) htmlDocGlobal; clickEvent.onclick += new mshtml.HTMLDocumentEvents2_onclickEventHandler (On_MouseClick); } } //else // { still loading } } //This function will rise when the user click's on web browser web page private bool On_MouseClick (mshtml.IHTMLEventObj e) { if (e.button.Equals (0)) { //Left-click mouse ArrayList m_PathToElement = new ArrayList(); IHTMLElement m_Parent = null; IHTMLElement m_Child = null; IHTMLElementCollection m_ParentCol = null; IEnumerator colEnum = null; //Receive pre-conditions m_Child = e.srcElement; //TEST_DEBUG: Child element may not have Parent elements !!! m_Parent = m_Child.parentElement; while (m_Child.parentElement != null) //if this is not the root element { { //Get the collection m_ParentCol = (IHTMLElementCollection) m_Parent.all; System.Windows.Forms.Application.DoEvents (); //let the system copy it colEnum = m_ParentCol.GetEnumerator (); colEnum.MoveNext (); //reset to '0' . . . . . Then I go throught collection and search for ckicked element till the root element. } } } I make some checks for received htmlDocGlobal and the size is different all the time :(( If you need the full source code please contact me by eMail "I have not failed. I've just found 10,000 ways that won't work." - Thomas

            J 1 Reply Last reply
            0
            • J Jasper4C

              Here you go the full (almost) source code //Web browser settings this.webBrowser.AddressBar = false; this.webBrowser.Dock = DockStyle.Fill; this.webBrowser.FullScreen = true; this.webBrowser.MenuBar = false; this.webBrowser.Offline = false; this.webBrowser.RegisterAsBrowser = true; this.webBrowser.RegisterAsDropTarget = false; this.webBrowser.Silent = true; this.webBrowser.StatusBar = false; this.webBrowser.TheaterMode = true; . . . private void webBrowser_DocumentComplete (object sender,AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e) { //Test counter - to see how many times this event rised ++this.tempCounter; if ( sender.Equals((object)this.webBrowser) && this.webBrowser.ReadyState.Equals(SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)) { MessageBox.Show ("Done loading\n\nLoaded " + this.tempCounter.ToString() +" times", "Document loaded"); //Receive global Document htmlDocGlobal = (mshtml.IHTMLDocument2) webBrowser.Document; if (clickEvent == null) { //Hook the event if not hooked till now clickEvent = (mshtml.HTMLDocumentEvents2_Event) htmlDocGlobal; clickEvent.onclick += new mshtml.HTMLDocumentEvents2_onclickEventHandler (On_MouseClick); } } //else // { still loading } } //This function will rise when the user click's on web browser web page private bool On_MouseClick (mshtml.IHTMLEventObj e) { if (e.button.Equals (0)) { //Left-click mouse ArrayList m_PathToElement = new ArrayList(); IHTMLElement m_Parent = null; IHTMLElement m_Child = null; IHTMLElementCollection m_ParentCol = null; IEnumerator colEnum = null; //Receive pre-conditions m_Child = e.srcElement; //TEST_DEBUG: Child element may not have Parent elements !!! m_Parent = m_Child.parentElement; while (m_Child.parentElement != null) //if this is not the root element { { //Get the collection m_ParentCol = (IHTMLElementCollection) m_Parent.all; System.Windows.Forms.Application.DoEvents (); //let the system copy it colEnum = m_ParentCol.GetEnumerator (); colEnum.MoveNext (); //reset to '0' . . . . . Then I go throught collection and search for ckicked element till the root element. } } } I make some checks for received htmlDocGlobal and the size is different all the time :(( If you need the full source code please contact me by eMail "I have not failed. I've just found 10,000 ways that won't work." - Thomas

              J Offline
              J Offline
              John Fisher
              wrote on last edited by
              #6

              It looks like you have 2 separate problems. First, test only the part that determines whether the page has finished loading. Once that is ready, then work on those other portions. The simpler you make each test, the easier it is to determine where the problem lies. If you need the complete page and all of its elements to finish loading before you do anything, then you'll need to track each sub-document and note when that has finished as well. Then, when they are all completely loaded, you can do your work. John
              "You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.

              J 1 Reply Last reply
              0
              • J John Fisher

                It looks like you have 2 separate problems. First, test only the part that determines whether the page has finished loading. Once that is ready, then work on those other portions. The simpler you make each test, the easier it is to determine where the problem lies. If you need the complete page and all of its elements to finish loading before you do anything, then you'll need to track each sub-document and note when that has finished as well. Then, when they are all completely loaded, you can do your work. John
                "You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.

                J Offline
                J Offline
                Jasper4C
                wrote on last edited by
                #7

                Yeah I thought about - checking all elements in the page for .ReadyState but I don't know how to do it :( Can you show me some code ??? (I check my prog on www.lenta.ru and this web page have 6 frames and 1 pop-up window) "I have not failed. I've just found 10,000 ways that won't work." - Thomas Alva Edison (1847-1931)

                J 1 Reply Last reply
                0
                • J Jasper4C

                  Yeah I thought about - checking all elements in the page for .ReadyState but I don't know how to do it :( Can you show me some code ??? (I check my prog on www.lenta.ru and this web page have 6 frames and 1 pop-up window) "I have not failed. I've just found 10,000 ways that won't work." - Thomas Alva Edison (1847-1931)

                  J Offline
                  J Offline
                  John Fisher
                  wrote on last edited by
                  #8

                  One way to do that would be to add each new document element to a collection when the document state changes. (If your ArrayList doesn't Contain() the document element, then Add() it.) Later, when the state of all those documents is complete, then test to see if you have the information you should have. John
                  "You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups