How to navigate to a location in a web browser component?

I have a Windows.NET form page and a WebBrowser component inside. I load the page inside a web browser using the navigation method, as in:

webBrowser1.Navigate("http://www.stackoverflow.com");

The length of the pages is longer than the height of the browser, so a vertical scrollbar appears. Now I want to move the scroll bar to a specific position. In particular, I want to find a specific world of text inside the page and scroll to this position.
This behavior is implemented in the built-in “Find” function of the browser, but I can’t figure out how to call the “Find” function from my code without the “Search” window appearing.
Although I do not want the Search box to appear if text matches are highlighted, this is welcome.

+3
source share
1 answer

You can do this with anchors.

webBrowser1.Navigate("http://www.stackoverflow.com#myAnchor");

and in your html define this:

<a id="myAnchor" />

This alone is not very flexible, but if you sequentially add anchor labels to the key structural parts of html, you can always skip to the section, block or div that you want.

+1
source

Source: https://habr.com/ru/post/1742839/


All Articles