Groups | Blog | Home
all groups > c# > january 2007 >

c# : WebBrowser navigating with DocumentStream to HTML anchors



Andy Bates
1/3/2007 10:09:09 PM
Hi -

I have a form hosting the above control. I can generate the HTML as a Stream
and set it in the control using:

this.webBrowser1.DocumentStream = myStreamOfHTML.

The problem is that there are anchor points in the document that I want to
move to either on open or later; question is how do I do this with the above
code?

As the above is setting the document from a stream the Url generally is just
set to about:blank.

The following works but means that I have to save the HTML to a disk file
which I don't want to do as it's sensitve data that is being displayed:

this.webBrowser1.Navigate(tempFileName + "#anchor");

Looking at the code in Reflector this disappears into the IWebBrowser2
Navigate2 method.

TIA

- Andy

Andy Bates
1/5/2007 6:04:29 AM
Found a solution.

I store the anchor I want to move to. Then in the DocumentComplete event I
retrieve all of the anchors in the document (GetElementsByTagName), look for
the fragment ID I want to move to and if found call ScrollIntoView on it.

[quoted text, click to view]

AddThis Social Bookmark Button