Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

Navigating to named anchors?

Hi There,

I using the web browser control in my app to view html documents, well, actually it's viewing XML documents that have a stylesheet defined.  In the stylesheet I set up some named anchors depending on what's in the XML etc etc. 

Nothing tricky so far.  My problem is - I want to provide a button outside of the web browser control to navigate (ie, scroll to) in the document to a particular anchor.

How the heck can I do this?  I'm using, but should be able to read any c# code enough to get the gist!

Brett O'Callaghan
Tuesday, February 3, 2004

If you don't mind late binding, you can do it in VB.Net with just:

myWebBrowserCtl.Document.location.hash = "foo"

Otherwise, you'll need something like:

Dim htmlDoc As IHTMLDocument2 = myWebBrowserCtl.Document
Dim location As IHTMLLocation = htmlDoc.Location
location.hash = "foo"

Refer to:

Aaron Boodman
Tuesday, February 3, 2004

Thank you *so* much!  It worked perfectly! 

Do you think I could find that anywhere in my msdn searches?  Not knowing exactly what to look for can always be a problem.

I'm an "option strict" guy, so what I ended up with is -

Dim htmlDoc As mshtml.IHTMLDocument2 =  CType(html.Document, mshtml.IHTMLDocument2)

Dim location As mshtml.IHTMLLocation = htmlDoc.location
location.hash = tsLocation

So easy when you know.

Brett O'Callaghan
Tuesday, February 3, 2004

*  Recent Topics

*  Fog Creek Home