How to get selected text from a webpage?

为君一笑 提交于 2019-12-25 04:22:46

问题


I need to retrieve only selected portion of a webpage (user open a webpage in web-browser control, then he/she would select some portion of a webpage, i just need only those selected portion/text) in vb.net in visual basic language. How to do ?

i am using microsoft visual studio 2008
Language: Visual Basic
FrameWork: vb.net 3.5


回答1:


Perhaps here are some answers for you(first post attachment):

Manipulate/Change/Form Fill data in webpages using the Webbrowser control




回答2:


In terms of IE's API, you can get the select text by getting the selection object via IHTMLDocument2::Selection the property, then create a range object via IHTMLSelectionObject::createRange. If the return range's type property is "Text", you can then query IHTMLTxtRange from it and get the selected text via IHTMLTxtRange::text.

It is unclear which webbrowser control you are referring to. There are 3 webbrowser controls in the .Net Framework, one in Windows Forms, one in WPF, and one in Silverlight. Anyway, you can call InvokeScript or use the unmanaged interface like csexwb's GetSelectedText, if one of the method is supported by your control library.

Next time mention which control library you are using when you ask the question. Merely mentioning the language you choose isn't enough to resolve the ambiguity in class names.



来源:https://stackoverflow.com/questions/3032776/how-to-get-selected-text-from-a-webpage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!