function FindIEWebBrowser: IWebBrowser2;
var
  tmpShell: IShellWindows;
  tmpIntf: IDispatch;
  tmpIE: IWebBrowser2;
  i, Count: Integer;
begin
  try
    if FWebBrowser = nil then
    begin
      Count := 0;
      repeat
        tmpShell := CoShellWindows.Create;
        for i := 0 to tmpShell.Count - 1 do
        begin
          tmpIntf := tmpShell.Item(i);
          if tmpIntf = nil then
            continue;
          tmpIntf.QueryInterface(IID_IWebBrowser2, tmpIE);          if tmpIE = nil then
            continue;
          if (Integer(Handle) = tmpIE.HWND) or
            FindIEWindow(Integer(tmpIE.HWND), Handle) then
         //这个话一直都报错 ,不知道为什么,
         //tmpIE 不为空啊 , IE浏览器已经打开了啊,不知道如何处理,求高手指点下                    FWebBrowser := tmpIE;
        end;
        Inc(Count);
        Sleep(50);
        Application.ProcessMessages;
      until (FWebBrowser <> nil) or (Count > 50);
    end;
    Result := FWebBrowser;
  except
  end;
end;function FindIEWindow(ParentHandle, ChildHandle: HWND): Boolean;
var
  tmpHandle: HWND;
begin
  tmpHandle := GetParent(ChildHandle);
  if tmpHandle = 0 then
  begin
    Result := false;
    Exit;
  end
  else
  begin
    if tmpHandle = ParentHandle then
    begin
      Result := true;
      Exit;
    end
    else
    begin
      Result := FindIEWindow(ParentHandle, tmpHandle);
    end;
  end;end;

解决方案 »

  1.   

    eg://调用网页脚本中的函数:procedure TForm1.Button1Click(Sender: TObject);
    begin
      WebBrowser1.OleObject.document.parentWindow.MB(); //HTML-Js  //如需指定脚本语言, 需要:
      WebBrowser1.OleObject.document.parentWindow.execScript('MB()','JavaScript'); //HTML-Js
    end;
    假如有这样的脚本:
    <script>
    function MB(){ 
      alert('HTML-Js');
    }
    </script>这样. 如果又返回值 就是你说的网址
    只要你 ss:=WebBrowser1.OleObject.document.parentWindow.MB() 
      

  2.   

    你要执行的脚本在mainFrame里面,可以这样WebBrowser1.Navigate('http://newmovie.gd.vnet.cn/gdvnet,0,tv_zhiqiang,0,11,1.page');然后webbrowser1.OleObject.document.parentWindow.execScript('chgPage(31)','JavaScript');