how whould i initate a set a events after the web broswer is done loading a page. The page has to load completly before the events happen. How whould i do this.
Printable View
how whould i initate a set a events after the web broswer is done loading a page. The page has to load completly before the events happen. How whould i do this.
have you not tried NavigateComplete2 then? or is it missing something / triggering before the page has finished loading?
hope thats the one your after.:)VB Code:
[Color=Blue]Private[/COLOR] [Color=Blue]Sub[/COLOR] AxWebBrowser1_NavigateComplete2([Color=Blue]ByVal[/COLOR] sender [Color=Blue]As[/COLOR] [Color=Blue]Object[/COLOR], [Color=Blue]ByVal[/COLOR] e [Color=Blue]As[/COLOR] AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event) [Color=Blue]Handles[/COLOR] AxWebBrowser1.NavigateComplete2 [Color=Green]'///[/COLOR] [Color=Green]use[/COLOR] [Color=Green]the[/COLOR] [Color=Green]NavigateComplete2[/COLOR] [Color=Green]Sub[/COLOR] [Color=Green]to[/COLOR] [Color=Green]handle[/COLOR] [Color=Green]events[/COLOR] [Color=Green]for[/COLOR] [Color=Green]a[/COLOR] [Color=Green]browser[/COLOR] [Color=Green]when[/COLOR] [Color=Green]it's[/COLOR] [Color=Green]completed[/COLOR] [Color=Green]loading. [/COLOR] [Color=Blue]End[/COLOR] [Color=Blue]Sub[/COLOR]
The events that I put in the private sub you posted happens before the page even starts to load.
well thats the sub that triggers upon a webpage being loaded, maybe if you specified the url within that sub and only carry out your code if it's navigated to that page it would work. like...
VB Code:
[COLOR=blue]If[/COLOR] AxWebBrowser1.LocationUrl = " Site name here " [COLOR=blue]Then[/COLOR] [COLOR=green]'///carry out your code here.[/COLOR] [COLOR=blue]Else[/COLOR] [COLOR=green]'/// Do nothing.[/COLOR] [COLOR=blue]End If[/COLOR]
I Still run into the problem of not KNowing how long it takes a page to load on someone elses computer. Theres got to be a way to make navigate2 work here is my code:
All this does is keep reloading yahoo.VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click name12 = TextBox1.Text url = "http://www.outwar.com/playersearch.php?search=" & name12 & "&submit=Search" Web1.Navigate(url) Label17.Text = name12 End Sub Private Sub web1_NavigateComplete2(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event) Handles Web1.NavigateComplete2 Web1.Navigate("www.yahoo.com") End Sub
That is because by calling navigate inside the Navigatecomplete2 event you make it recursive. In other words everytime the page at yahoo.com finishs loading it calls the complete event which in turn then calls for another yahoo page. You can listen to dynamic and inside the complete event check the url and only navigate again if its not yahoo. The code he posted would be put it the Complete event.
ok i see, but is there a way to use navigate 2 to detect when the browser is done loading?
The NavigateComplete2 event only fires when a page (any page) finishes loading. Well any page loaded into the associated AxWeb Browser control.
So how to I make the cose i posted above work?
How is it broken? Or what is it suppose to do?
it keeps loading yahoo and doesnt load the url variable first. What i really need to do is navigate to url then after that is finished loading get the html(i know how to do this)
If you don't want it to go to yahoo then why is that there? I'm confused.VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click name12 = TextBox1.Text url = "http://www.outwar.com/playersearch.php?search=" & name12 & "&submit=Search" Web1.Navigate(url) Label17.Text = name12 End Sub Private Sub web1_NavigateComplete2(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event) Handles Web1.NavigateComplete2 'put your code to get html here End Sub
I put it there to see what page it whould load first, the page i wanted or the page that was under naviagte2. BUt any way when i use this code the events under navigate2 always happen first.
Huh? Also regarding your test, as soon as the first page loaded then it would immediately change to the yahoo page so it doesn't really work also the yahoo page doesn't get called until after the first one is loaded in fact that is what fires it so the one in the button call will always load first.
When you say loaded do you mean loaded completly or just starting?
For Example is this instance the msgbox is displayed first and ok must be pressed before the page is even starting to load
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click name12 = TextBox1.Text url = "http://www.outwar.com/playersearch.php?search=" & name12 & "&submit=Search" Web1.Navigate(url) Label17.Text = name12 End Sub Private Sub web1_NavigateComplete2(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event) Handles Web1.NavigateComplete2 msgbox("Test") End Sub
I think we should understand first when I say loaded I mean it is downloaded, the browser may still be rendering or showing it but it should be completely downloaded or loaded. So the msgbox may halt the thread from showing the page but it 'should' be completed or completely loaded (aka downloaded). In other words the webbrowser should have all of the html from the source.
So you are saying that i can download the html even though the broswer is still rendering?
That 'should' be the case.
ok thanks, thats what i needed to know
if you want the source of the html , use Document_Complete not Navigate_Complete. eg:
VB Code:
[Color=Blue]Private[/COLOR] [Color=Blue]Sub[/COLOR] AxWebBrowser1_DocumentComplete([Color=Blue]ByVal[/COLOR] sender [Color=Blue]As[/COLOR] [Color=Blue]Object[/COLOR], [Color=Blue]ByVal[/COLOR] e [Color=Blue]As[/COLOR] AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent) [Color=Blue]Handles[/COLOR] AxWebBrowser1.DocumentComplete [Color=Green]'///[/COLOR] [Color=Green]doc[/COLOR] [Color=Green]is[/COLOR] [Color=Green]completely[/COLOR] [Color=Green]loaded[/COLOR] [Color=Green]now [/COLOR] MessageBox.Show(AxWebBrowser1.Document.documentelement.innerhtml) [Color=Blue]End[/COLOR] [Color=Blue]Sub[/COLOR]