Thanks to Bruce Deam.
Bruce noticed that the example Get all text or the selected text from a WebBrowser control by using the control's methods doesn't work if the selected text is inside a frame. This example searches the Web page's frames to find the selected text.
Function getSelectedDocument searches for a frame that contains selected text. First it checks the selection.Type property of the HTMLDocument that it received as a parameter to see if that object has selected text. If it contains selected text, the function returns that document.
If the document does not contain selected text, the routine loops through the document's frames. For each frame, the function calls itself recursively, passing itself the frame's Document object. If the recursive call returns a document containing selected text, the function passes that document up to its caller.
|