delphi 用IWebbrowser2如何获取IE地址栏的网址?请高手帮忙...

解决方案 »

  1.   


    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs,SHDocVw, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
      shell:IShellWindows;
      i,count:Integer;
      disp:IDispatch;
      v:OleVariant;
      ie:IWebBrowser2;
    begin
      shell := CoShellWindows.Create;
      count := shell.Count;
      for i:=0 to count - 1 do
      begin
        v := i;
        disp := shell.Item(v);
        if disp <> nil then
        begin
          disp.QueryInterface(IWebBrowser2,ie);
          if ie <> nil then
          begin
            ShowMessage('程序:'+ie.LocationName+' 网址:'+ie.LocationURL);
          end;
        end;
      end;
    end;end.
      

  2.   

    用 TEmbeddedWB;
    很方便; 
    获取cookies:   EmbeddedWB1.Cookie;
    获取当前页面网址:EmbeddedWB1.LocationURL;
    获取页面标题:EmbeddedWB1.LocationName;还有很多封装好的方法。记得用最新版的。老版本好像没有这些方法。    property LocationName: WideString index 210 read GetWideStringProp;
        property LocationURL: WideString index 211 read GetWideStringProp;function TCustomEmbeddedWB._getCookie: WideString;
    var
      D: IHTMLDocument2;
    begin
      if Supports(Document, IHTMLDocument2, D) then
        Result := OleObject.Document.Cookie
      else
        Result := '';
    end;