WebBrowser和OLECMDID_SELECTALL [英] WebBrowser and OLECMDID_SELECTALL
本文介绍了WebBrowser和OLECMDID_SELECTALL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用以下网址打开Google网页时:
When I open the Google web page using:
WebBrowser1.Navigate('http://www.google.com.au/advanced_search?hl=en');
它会随着光标在编辑框中打开。
因此,当我使用:
it opens with the cursor in the edit box.
So when I use:
WebBrowser1.ExecWB(OLECMDID_SELECTALL,OLECMDEXECOPT_PROMPTUSER,vaIn, vaOut);
它只复制光标所在的位置。不是整个网页,这是我想要复制的。
我的代码是:
it only copies where the cursor is. Not the whole web page, which is what I want to copy. my code is:
procedure Pause()
begin
//code to pause until page loads.
end;
procedure TForm2.Button22Click(Sender: TObject);
var s:String;
vaIn, vaOut: OleVariant;
begin
s:='http://www.google.com.au/advanced_search?hl=en';
WebBrowser1.Navigate(s);
while WebBrowser1.ReadyState <> READYSTATE_COMPLETE do
begin
Pause(1000);
end;
//------->I need to put code here so the SELECTALL line of code works.<----------
//------->So the cursor isn't in to editbox but as if it has clicked <----------
//------->the webpage <----------
WebBrowser1.ExecWB(OLECMDID_SELECTALL,OLECMDEXECOPT_PROMPTUSER,vaIn, vaOut);
end;
如何选择整个网页?
推荐答案
尝试在选择所有内容之前集中身体:
Try focusing the body before selecting all:
((WebBrowser1.Document as IHTMLDocument2).body as IHTMLElement2).focus();
WebBrowser1.ExecWB(OLECMDID_SELECTALL, OLECMDEXECOPT_PROMPTUSER, vaIn, vaOut);
这样说更好的方法是使用 document.body.innerText
来抓取文本,而不是模拟像你这样的选择/复制。
With that said a better approach would be to use document.body.innerText
to grab the text, instead of simulating a select/copy like you do.
这篇关于WebBrowser和OLECMDID_SELECTALL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文