开发者

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.


You can try this code:

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


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 #.


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
}


One way...

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜