I try to have the find dialog feature in my webbroser control, it should search several words (forward) and highlight them. I tried the following code from this MSDN question
private bool FindFirst(string text)
{
IHTMLDocument2 doc = (IHTMLDocument2)browserInstance.Document;
IHTMLSelectionObject sel = (IHTMLSelectionObject)doc.selection;
sel.empty(); // get an empty selection, so we start from the beginning
IHTMLTxtRange rng = (IHTMLTxtRange)sel.createRange();
if (rng.findText(text, 1000000000, 0))
{
rng.select();
return true;
}
return false;
}
However this code and the code in the original question search the entire document and use range = body.createTextRange()
to create a range, I would like to search within a specific element (for example just text in a specific div
)
How can I do that?