reloading a webbrowser control

Glowman
Glowman used Ask the Experts™
on
I have a web browser control in my project that I am loading a local htm file into.  I am getting frusterated by the fact that everytime I reload the htm doc it won't keep the cursor at the bottom.  What I am doing is appending to the htm file and issuing the refresh method on the control.  I want the cursor to stay at the bottom of the doc instead of just remaining where it is.  Is this possible to do?
G

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2006

Commented:
Hello Glowman,

When you know one tag on the bottom of the page you could try

Dim allAnchors as IHTMLElementCollection

Set allAnchors=WebBrowser1.Document.Tags("a")

allAnchors("NameOfYourTagHere").ScrollIntoView

and it will scroll to the tag

HAGD:O)Bruintje

Author

Commented:
brun,
Unfourtunatly I have no tags in the *.htm doc that I am appending to.  It is for a chat app and each time a user enters text it appends to the *.htm.  Is there a property or another collection that can help me keep my document at the bottom?

G
I dont recall the exact syntax, but you could try:

WebBrowser.Document.parentWindow.scrollTo 0, 12000

where the 'y' coordinate is some large value.


You may want to rethink how you are appending to this htm document.  If you do all of your updating dynamically via the DOM of the webbrowser, you could probably avoid these problems (and any need to perform a refresh).
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Top Expert 2006

Commented:
AzraSound, curious here >> and any need to perform a refresh

how would you do that? just adding to the DOM document?

or should i ask a seperate Q for that :)

:O)Bruintje

Author

Commented:
I tired that, just adding to the htm document but without the refresh call it never changes even if I save the doc (which won't work anyways).  In your example of assigning a value to the Y cord what is that actaully doing?
G
That would just scroll your window down, so there is a good chance you would still see some sort of refresh (the page reloads, then scrolls to the bottom)


bruintje,
I would imagine you could just add to the DOM via code, but Glowman says that it never updated.  Anytime I have ever loaded a page into the webbrowser control, though, and did a simple WebBrowser.write strHTMl it seemed to update immediately.

Perhaps some code can be posted?

Author

Commented:
Azra,
Do you mean I can append the htm document as it is inside the webbrowser control without making changes to the local file?

G
Yes, here is a simple example:


Private Sub Command1_Click()
    Call AppendHTML(WebBrowser1, "Hello<br>")
End Sub

Private Sub Form_Load()
    WebBrowser1.Navigate "about:blank"
End Sub


Function AppendHTML(ByRef WB As WebBrowser, ByVal NewString As String)
    WB.Document.body.insertAdjacentHTML "BeforeEnd", NewString
End Function
Top Expert 2006

Commented:
cool! didn't knew was that easy ...
Author of the Year 2009

Commented:
Hi Glowman,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept AzraSound's comment(s) as an answer.

Glowman, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept THIS comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial