我自己用delphi的webbrowser做了个小的浏览器。但是每次打开新的窗口(比如输入csdn的密码确定后都会自动打开IE),怎样做才能使他还是打开我做的浏览器的窗口呢??

解决方案 »

  1.   

    修改注册表HKEY_CLASSES_ROOT\http\shell\open\command的键值为你的浏览器路径
    uses Registry;procedure setyourIE;
    var
      Reg:TRegistry;
    begin
      Reg:= TRegistry.Create;
      with Reg do
        begin
          RootKey:=HKEY_CLASSES_ROOT;
          if OpenKey('htmlfile\shell',false) then
             writeString('','yourIE');
          CloseKey;
          if OpenKey('htmlfile\shell\yourIE\command',true) then
             writeString('','c:\yourIE.exe "%1"');
          CloseKey;      if OpenKey('http\shell',false) then
             writeString('','yourIE');
          CloseKey;      if OpenKey('http\shell\yourIE\command',true) then
             writeString('','c:\yourIE.exe "%1"');
          CloseKey;      if OpenKey('https\shell',false) then
             writeString('','yourIE');
          CloseKey;      if OpenKey('https\shell\yourIE\command',true) then
             writeString('','c:\yourIE.exe "%1"');
          CloseKey;
          free;
        end;
    end;
    function check: boolean;
    var
      Reg:TRegistry;
    begin
      result:=true;
      Reg:= TRegistry.Create;
      with Reg do
        begin
          RootKey:=HKEY_CLASSES_ROOT;
          if OpenKey('htmlfile\shell',false) then
             if readString('')<>'yourIE' then result:=false;
          CloseKey;
          if OpenKey('http\shell',false) then
             if readString('')<>'yourIE' then result:=false;
          CloseKey;
          if OpenKey('https\shell',false) then
             if readString('')<>'yourIE' then result:=false;
          CloseKey;
          free;
        end;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      if not check then
         if MessageDlg('yourIE不是当前的默认网络浏览器'+#10#13
            +'你是否愿意yourIE设置为你的默认网络浏览器',mtConfirmation, [mbYes, mbNo], 0) = mrYes then
         setyourIE;
    end;
      

  2.   

    假设你原来的叫WebBrowser1,你要新建一个webbrowser,比如WebBrowser2,
    然后在WebBrowser1的OnNewWindow2的事件中:
    procedure TForm1.WebBrowser1NewWindow2(Sender: TObject; var ppDisp: IDispatch;
      var Cancel: WordBool);
    begin
      ppDisp := WebBrowser2.Application;
    end;
    这样新的窗口会转到你新建的WebBrowser2中。