Mostafa Mahdieh
Mostafa Mahdieh

Reputation: 986

Find text in webbrowser control

I have a web browser control, already navigated to a page. Now I want to search for a specific text in the page, and scroll to the first occurrence.

Being able to scroll to other occurrences is a bonus.

Upvotes: 2

Views: 6808

Answers (4)

Rusty Nail
Rusty Nail

Reputation: 2710

One way...

Use the Ctrl + F Key to invoke Find, native to the WebBrowser Control?

Upvotes: 0

Chiwda
Chiwda

Reputation: 1344

See this if it helps:

string PageSource = null;
PageSource = WebBrowser1.Document.Body.InnerHtml();
if (Strings.InStr(PageSource, stringtoFind) > 0) {
  ...insert an Anchor tag here and then use 
   WebBrowser1.Navigate to go to the the new URL with the #Anchor tag
} else {
...whatever else
}

Upvotes: 0

GenZiy
GenZiy

Reputation: 1447

You can try this code:

webBrowser1.Select(); SendKeys.Send("^f");

Upvotes: 1

Cheng Chen
Cheng Chen

Reputation: 43513

I don't know if it works in a WebBroswer. We make the broswer(IE/FF/etc) window scroll to some text with the following code:

//source code of http://www.sample.com/sample.html
<html>
...
<span name="aim">KeyWord</span>
...
</html>

If I want the window to scroll to the "KeyWord", simply visit http://www.sample.com/sample.html#aim

Using string document = myWebBrowser.DocumentText to get the source code of the page, and search the text in the string, get its node name, and navigate it using #.

Upvotes: 0

Related Questions