当我使用以下方法打开Goog​​le网页时:

WebBrowser1.Navigate('http://www.google.com.au/advanced_search?hl=en');


随即在编辑框中显示光标。
所以当我使用:

WebBrowser1.ExecWB(OLECMDID_SELECTALL,OLECMDEXECOPT_PROMPTUSER,vaIn, vaOut);


它仅复制光标所在的位置。不是整个网页,这是我要复制的内容。
我的代码是:

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;


如何选择整个网页?

最佳答案

在全部选择之前,尝试将身体聚焦:

((WebBrowser1.Document as IHTMLDocument2).body as IHTMLElement2).focus();
WebBrowser1.ExecWB(OLECMDID_SELECTALL, OLECMDEXECOPT_PROMPTUSER, vaIn, vaOut);


话虽如此,一种更好的方法是使用document.body.innerText捕获文本,而不是像您那样模拟选择/复制。

10-08 04:48