WebBrowser navigating with DocumentStream to HTML anchors

  • Thread starter Thread starter Andy Bates
  • Start date Start date
A

Andy Bates

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
 
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.
 
Back
Top