WebBrowser doesn't have a "find" method?  
Author Message
JackMit





PostPosted: Windows Forms General, WebBrowser doesn't have a "find" method? Top

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


Windows Forms19  
 
 
ahmedilyas





PostPosted: Windows Forms General, WebBrowser doesn't have a "find" method? Top

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



 
 
JackMit





PostPosted: Windows Forms General, WebBrowser doesn't have a "find" method? Top

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.

 
 
ahmedilyas





PostPosted: Windows Forms General, WebBrowser doesn't have a "find" method? Top

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



 
 
DMan1





PostPosted: Windows Forms General, WebBrowser doesn't have a "find" method? Top

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



 
 
JackMit





PostPosted: Windows Forms General, WebBrowser doesn't have a "find" method? Top

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





PostPosted: Windows Forms General, WebBrowser doesn't have a "find" method? Top

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





PostPosted: Windows Forms General, WebBrowser doesn't have a "find" method? Top

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

 
 
JRQ





PostPosted: Windows Forms General, WebBrowser doesn't have a "find" method? Top

Have you tried just using the internal Find Dialog-box of the WebBrowser In VS2003 you can execute the Find Dialog-box of IE when you send the command using WBExec().