webhtmlviewer and anchors

I’ve created some html and loaded it into an htmlviewer but I don’t necessarily want the viewer to display at the top of the page. Is there a way to have the viewer open at or scroll to an anchor in the html?

mypage.html#anchor ?

But in what context could you tell the htmlviewer to access that url as the actual html isn’t in some file to be linked to?

If you have placed an anchor named anchor1 by placing this code in your page

<a name="anchor1"></a>

The correct way to load it in the HTMLViewer for it to display starting on top with the anchor is by calling it’s URL with #anchor1 :

HTMLViewer.url = "http://mydomain.com/mypage.html#anchor1

The HTMLViewer will automatically place the page at the anchor. Any browser will do too.

Alternatively :

HTMLViewer.url = HTMLViewer.url+"#anchor1"

There is no mypage.html to link to. The html is a string variable used with loadpage(). I suppose I could try the added step of writing the string to a file and linking to it.

And I missed your alternative of adding to the url after it has loaded. That sort of works but I think it puts me in the right direction. Thanks.

If you are using loadpage, why not create several sections in your HTML string ?

I’m not sure what you mean by sections, but it made me look through the loadpage documentation. That in turn gave me the idea to add a little javascript function in the body onload event that scrolls to the anchor. Works great so far.

The idea was simply to divide the page in several pages, each corresponding to what you had previously set as anchor. But if you achieve what you want through JavaScript, that is great.

My page is essentially a list of dates and I just needed one anchor so that the current date appeared at the top but also allowing the user to scroll up to past dates if they desired.