用webborwser访问一个url,在显示新页面的时候,会弹出一个窗口,询问是确认或取消浏览.我想问 如何实现自动对这个确认按钮进行点击.
页面内容如下:
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="colorring.css" rel="stylesheet" type="text/css">
<link href="images/blue/color.css" rel="stylesheet" type="text/css">
</head>
<script src="pubfun/JsFun.js"></script><body leftmargin="0" topmargin="0"><form name="inputForm" method="post" action="largess.jsp">
<input type="hidden" name="id" value="1234">
<input type="hidden" value="123456789" name="phone">
<input type="hidden" value="" name="leavewords">
</form>
<script language="JavaScript">
                var  strConfirm = "您确认要浏览吗?";
                if (confirm(strConfirm)) {
                  document.inputForm.submit();
                }
                else{
                  document.URL = '?grouptype=1';
                }
                </script>
</body>
</html>

解决方案 »

  1.   

    有空多到
    www.51merit.com
    看看!
    procedure TFrmMain.Timer2Timer(Sender: TObject);
    var
        H: HWND;
        text: array[0..255] of char;
        s: string;
    begin
        h := findwindow(nil, 'Internet Explorer 脚本错误'); //查找到窗口#32770,&#8217;#32770&#8216;用spy++查出来的。    if H > 0 then SendMessage(h, WM_SYSCOMMAND, SC_CLOSE, 0);    h := findwindow(nil, 'Microsoft Internet Explorer'); //查找到窗口#32770,&#8217;#32770&#8216;用spy++查出来的。
        if H > 0 then SendMessage(h, WM_SYSCOMMAND, SC_CLOSE, 0);    h := findwindow(nil, '添加到收藏夹'); //查找到窗口#32770,&#8217;#32770&#8216;用spy++查出来的。
        if H > 0 then SendMessage(h, WM_SYSCOMMAND, SC_CLOSE, 0);    h := findwindow(nil, '安全警报'); //查找到窗口#32770,&#8217;#32770&#8216;用spy++查出来的。
        if H > 0 then SendMessage(h, WM_SYSCOMMAND, SC_CLOSE, 0);
        h := findwindow(nil, 'Symantec AntiVirus 通知'); //查找到窗口#32770,&#8217;#32770&#8216;用spy++查出来的。
        if H > 0 then SendMessage(h, WM_SYSCOMMAND, SC_CLOSE, 0);    h := GetActiveWindow();
        GetWindowText(h, @text, 255);
        s := strpas(text);
        if pos('Microsoft Internet Explorer', s) > 0 then SendMessage(h, WM_SYSCOMMAND, SC_CLOSE, 0);    //回位于最顶部的具有输入焦点的窗口句柄
    end;
      

  2.   

    模拟回车
      keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0);
      keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP,0);
      

  3.   

    各个大大,我是第一次使用这个 webbrowser,所以对控件本身不太了解,所以各个大大最好有例子告诉我下,谢谢
      

  4.   

    to xixuemao
    我用你的方法试过了,不行
      

  5.   

    这个问题我我解决了,得到zsp869999的启发,使用findwindow查找句柄的方式得到弹出窗口的句柄,然后使用findwindowex得到确定按钮的句柄。就可以实现对弹出窗口的确定按钮进行点击了。
    procedure TForm1.Timer1Timer(Sender: TObject);
    var
        H,hc: HWND;begin
        Timer1.Enabled := False;
        
        if H > 0 then SendMessage(h, WM_SYSCOMMAND, SC_CLOSE, 0);  }   h := findwindow(nil, 'Microsoft Internet Explorer');     if H > 0 then
        begin
            hc := FindWindowEx(h,0,'Button','确定');
            SendMessage(hc, BM_CLICK, 0, 0);
      
        end;
       
    end;
      

  6.   

    上面代码有误,现在重新贴
    procedure TForm1.Timer1Timer(Sender: TObject);
    var
        H,hc: HWND;begin
        Timer1.Enabled := False;
        
          h := findwindow(nil, 'Microsoft Internet Explorer');   
      if H > 0 then
        begin
            hc := FindWindowEx(h,0,'Button','确定');
            SendMessage(hc, BM_CLICK, 0, 0);
      
        end;
    end;