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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Web browsers control - getting newest version of page... 2

Status
Not open for further replies.

mwolf00

Programmer
Nov 5, 2001
4,177
US
How can I make sure that I am not getting a cached version of a web page when I navigate to it?

Code:
    Web1.Navigate URL
    Web1.SetFocus
    Web1.Refresh
refreshed the page I came from and
Code:
Private Sub Web1_DocumentComplete(ByVal Text As String)
    Web1.Refresh
End Sub

causes an endless loop. Do I need to set a variable and check its value to make it happen once or is there an easier way?


Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook

zen.gif

 
To ensure that you get a non-cached copy of a web page, use the Refresh2 method with REFRESH_COMPLETELY as the parameter, instead of the Refresh method. Here's what MSDN has to say about it:

Refresh2 Method

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

Reloads the page currently displayed in the WebBrowser control. Unlike the Refresh method, this method contains a parameter that specifies the refresh level.

Syntax

object.Refresh2 [Level]
Parameters

object
Required. An object expression that evaluates to an object in the Applies To list.
Level
Optional. A constant or value that specifies the refresh level. It can be one of the following constants or values.
REFRESH_NORMAL 0 Perform a lightweight refresh that does not include sending the HTTP "pragma:nocache" header to the server.
REFRESH_IFEXPIRED 1 Perform a lightweight refresh if the page has expired.
REFRESH_COMPLETELY 3 Perform a full refresh that includes sending a "pragma:nocache" header to the server (HTTP URLs only).

Remarks

The "pragma:nocache" header tells the server not to return a cached copy. This ensures that the information is as fresh as possible. Browsers typically send this header when the user selects refresh, but the header can cause problems for some servers.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
WOW! I was kinda wondering about this as well. Jebenson comes through again! What a super star!

LF

"As far as the laws of mathematics refer to reality, they are not certain; as far as they are certain, they do not refer to reality."--Albert Einstein
 
jebenson - Thanks for the response. However, my question is when, in my code, do I call the refresh to ensure I get the new page instead of the current page?

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook

zen.gif

 
Guys, I know I'm not on the subject, but I just like so much the signature of mwolf00 ("Programming today...")

I recently heard a good one too:
A realy advanced programmer is the one that can code whistling the source code at the audio connector of an Spectrum machine (the old HC).

I know I'm a bit late, but A Happy New Year to all of you!
 
>> (Q1) when, in my code, do I call the refresh to ensure I get the new page instead of the current page?

Right after you navigate...

>> (Q2) Is that not possible to insert a timer and Refresh the Web1 in the interval of the timer?

Yes...

Code:
Private Sub Form_Load()
  Timer1.Enabled = False '(Q2)
  wb1.Navigate2 "url"
  wb1.Refresh2 3         '(Q1)
End Sub

'(Q2)...
Private Sub wb1_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
  Timer1.Interval = 30000 '30 * 1000 = 30 seconds
  Timer1.Enabled = True
End Sub

'(Q2)...
Private Sub Timer1_Timer()
  wb1.Refresh2
End Sub


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Cube101 -

Like my original post states, when I try what you are suggesting for Q1, I get the previous page. For instance if the current page in web1 is " and I navigate to " and immediately refresh, Google gets refreshed and I never get to yahoo...

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook

zen.gif

 
try adding this in between:

Code:
wb1.Navigate "..."
[b]do: doevents: loop until wb1.ReadyState = READYSTATE_COMPLETE[/b]
wb1.Refresh2 3

That line of code fixes MANY problems like this when dealing with the webbrowser...

I usually make a small sub for it...
Code:
Sub WaitForLoad()
  Do: DoEvents: Loop Until wb1.ReadyState = READYSTATE_COMPLETE
End Sub

Hope this helps...



PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
[highlight]Thank you cube. Once again, you've solved my problem![/highlight]

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook

zen.gif

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top