Hey, I'm a novice here and I've been looking though the MSDN documentation on the WebBrowser control and noticed there was no method for finding text in a document. This is a pretty serious omission. Is there a way of getting this functionality? |
| JackMit Thursday, November 30, 2006 2:34 PM |
this.theWebBrowserControl.DocumentText; //gets or sets the HTML Text to be displayed
so what you would have to do is some Regex- Regular Expressions to find the word you are after. Once you find it, you will then have to highlight it in some way.
Take a look at this, check to see if it has the find feature:
http://msdn2.microsoft.com/en-us/library/ms379558(vs.80).aspx
perhaps there is some command you can invoke to do a search using the InvokeMember method? I'm not sure, just thinking aloud
http://msdn2.microsoft.com/en-us/library/system.windows.forms.htmlelement.invokemember.aspx |
| ahmedilyas Thursday, November 30, 2006 3:04 PM |
As ahmed suggest, finding it is the easy part...to highlight the find will take manipulating the html :
Dim wb As New WebBrowser
wb.Navigate("http://www.google.com")
Dim TheText As String = wb.DocumentText
Dim SearchString As String = "Google"
If TheText.Contains(SearchString) Then
'do somthing
End If |
| DMan1 Thursday, November 30, 2006 3:07 PM |
Have you tried just using the internal FindDialog-box of the WebBrowser? In VS2003 you can execute the Find Dialog-box of IE when you send the command using WBExec(). |
| JRQ Friday, December 01, 2006 5:25 PM |
you can make your own find method by searching through text in the documentText property perhaps. Remember, the webbrowser control is just a core functionality of IE, no extra fancy bits like favorites/IE options/Search box etc...
|
| ahmedilyas Thursday, November 30, 2006 2:45 PM |
I don't see that property in the link I provided. There is a "Document" property but no documentText. I'm okay with making my own method, but I don't see how I'd achieve it since I need a way to select a word in the document.
|
| JackMit Thursday, November 30, 2006 2:53 PM |
this.theWebBrowserControl.DocumentText; //gets or sets the HTML Text to be displayed
so what you would have to do is some Regex- Regular Expressions to find the word you are after. Once you find it, you will then have to highlight it in some way.
Take a look at this, check to see if it has the find feature:
http://msdn2.microsoft.com/en-us/library/ms379558(vs.80).aspx
perhaps there is some command you can invoke to do a search using the InvokeMember method? I'm not sure, just thinking aloud
http://msdn2.microsoft.com/en-us/library/system.windows.forms.htmlelement.invokemember.aspx |
| ahmedilyas Thursday, November 30, 2006 3:04 PM |
As ahmed suggest, finding it is the easy part...to highlight the find will take manipulating the html :
Dim wb As New WebBrowser
wb.Navigate("http://www.google.com")
Dim TheText As String = wb.DocumentText
Dim SearchString As String = "Google"
If TheText.Contains(SearchString) Then
'do somthing
End If |
| DMan1 Thursday, November 30, 2006 3:07 PM |
| this.theWebBrowserControl.DocumentText; //gets or sets the HTML Text to be displayed |
|
It's weird that they didn't include this in the documentation...I hope it's not limited to VB only.
| Take a look at this, check to see if it has the find feature: |
|
I don't think it does...or at least, they don't mention it. I wonder how commercial IE-based browsers like Maxthon managed to implement find?
Thanks for the help by the way. |
| JackMit Thursday, November 30, 2006 4:42 PM |
I've decided that the best way to do it is by executing some javascript code that searches for the term and highlights the result(s). All I need to know is: Is there an easy way to execute javascript code on the currently displaying page?
|
| JackMit Thursday, November 30, 2006 5:31 PM |
Anyone know of a method that does this? Apple's WebKit has a method called stringByEvaluatingJavaScriptFromString that essentially does this, so I'm hoping MSHTML has an equivalent...
|
| JackMit Friday, December 01, 2006 1:31 AM |
Have you tried just using the internal FindDialog-box of the WebBrowser? In VS2003 you can execute the Find Dialog-box of IE when you send the command using WBExec(). |
| JRQ Friday, December 01, 2006 5:25 PM |