2010-10-20 47 views

回答

0

我不知道它是否在WebBroswer。我们做broswer(IE/FF /等)窗口滚动到一些文字用下面的代码:

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

如果我想在窗口滚动到“关键字”,只需访问http://www.sample.com/sample.html#aim

使用string document = myWebBrowser.DocumentText获取页面的源代码,并搜索字符串中的文本,获取其节点名称,然后使用#进行导航。

+0

实际上问题没有滚动到特定的节点;已经完成。找到与搜索查询匹配的文本的选择是主要问题。 – 2010-10-20 18:55:19

+0

@Mostafa Mahdieh:看我的编辑。 – 2010-10-21 02:12:15

+0

我必须在这里添加一些细节...在文本中搜索会得到字符串中的一个索引。找到包含该字符串的节点并不是那么简单:匹配的文本可能是合并到节点中的多个文本节点的结果。 – 2010-10-22 09:40:29

1

你可以试试这个代码:

webBrowser1.Select(); SendKeys.Send(“^ f”);

0

看到这个,如果有帮助:

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 
} 
0

的一种方式......

使用Ctrl + F键来调用Find,原产于WebBrowser控件?