using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;  //Thread.Sleep(100);
namespace webdemo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            webBrowser1.Navigate("http://WWW.XXX.COM");        }
        private void button1_Click(object sender, EventArgs e)
        {
            //此处还设置了个timer事件实现不停的点击
            System.Windows.Forms.HtmlElement btn_Submit = this.webBrowser1.Document.GetElementById("Submit"); //点击关闭按钮,这个括号中的submit需要改成什么吗?
            btn_Submit.InvokeMember("click"); //让我使用new关键字设置实例,该如何设置??
        }    }
}//我找到的关闭按钮的HTML源代码
//<center>
//<span id="close_button" class="border_button" style="visibility:hidden; height:20px;" onclick="window.parent.closeResult();">关闭</span>
//</center>
//</div>
上面的该如何改啊,我是用了WB控件,获取WB网页中的元素并调用里面的方法事件进行自动操作,现在还有点问题,帮帮我怎么改啊,代码中我也写了几个问题,求解

解决方案 »

  1.   

    补充问下,这个HTML中的onclick方法可以用吗?怎么用?
      

  2.   

    应该只要把这句
     System.Windows.Forms.HtmlElement btn_Submit = this.webBrowser1.Document.GetElementById("Submit");
    改写为:
     System.Windows.Forms.HtmlElement btn_Submit = this.webBrowser1.Document.GetElementById("close_button");
    就可以了。
      

  3.   

    btn_Submit.InvokeMember("click"); //让我使用new关键字创建对象实例,让我检查对象是否为空?该如何设置??
      

  4.   

    using mshtml;//为了使用IHTMLWindow2接口,必须的添加对非托管COM对象的托管包装,在项目引用里面选择COM选项卡,添加Microsoft HTML Object Library即可 
    private void button1_Click(object sender, EventArgs e) 
            { 
                string scripts ="window.closeResult();"; 
    IHTMLWindow2 win = (IHTMLWindow2)webBrowser1.Document.Window.DomWindow; 
    win.execScript(scripts, "Javascript");        } 
      

  5.   

     private void Form1_Load(object sender, EventArgs e)
            {
                webBrowser1.Navigate("http://www.baidu.com"); 
            }        private void button1_Click(object sender, EventArgs e)
            {
                //此处还设置了个timer事件实现不停的点击 
                System.Windows.Forms.HtmlElement btn_Submit = this.webBrowser1.Document.GetElementById("sb"); //点击关闭按钮,这个括号中的submit需要改成什么吗? 
                btn_Submit.InvokeMember("click"); //让我使用new关键字设置实例,该如何设置?? 
            }我试了下百度,它那个“百度一下”的按钮的id为"sb",我怎么行的啊?你确认你第一句获得了那个btn_Submit了吗?
      

  6.   

    window.parent.closeResult();可能是frameset或者iframe,你要看看你的webBrowser1的URI是指到父页面还是子页面
      

  7.   

    那就是string scripts ="window.closeResult();"; 
    你看下源文件closeResult这个函数在哪里了
      

  8.   


    你要先看下你的页面,是不是有window.parent.closeResult();
    也就是说,你在WEBBROWSER里可能没有开父页面,也就调不到closeResult()
      

  9.   

    这个WEB只显示的是当前页面啊,也就是子页面,我只是要把当前子页面的一个关闭按钮点击下就行了,点击了这个关闭按钮就消失了,就这样,回不到子页面,有什么方法吗?
      

  10.   


    我是拿的子页面的源代码啊,拿了一部分
    /head>
    <script type="text/javascript">
    window.parent.document.getElementById("loading_image").style.display = "none";
    </script>
    <center>
    <span id="close_button" class="border_button" style="visibility:hidden; height:20px;" onclick="window.parent.closeResult();">关闭</span>
    </center>
    </div>
    </body><script type="text/javascript">
    var ifr = window.parent.document.getElementById("result_iframe");
    ifr.style.height = getEl("_all").offsetHeight +15;
      

  11.   

    这个WEB只显示的是当前页面啊,也就是子页面,我只是要把当前子页面的一个关闭按钮点击下就行了,点击了这个关闭按钮就消失了,就这样,回不到父页面,还是在子页面,有什么方法吗?
      

  12.   


    这个按钮执行的是父页面的js啊,onclick="window.parent.closeResult();
    如果你WEBBROWSER不载入他的父页面的话,那就自己在后台代码里帮他写了
    //这是关闭页面的
                string scripts = "window.close();";
                mshtml.IHTMLWindow2 win = (IHTMLWindow2)webBrowser1.Document.Window.DomWindow;
                win.execScript(scripts, "Javascript");
      

  13.   

    //此处还设置了个timer事件实现不停的点击 
                System.Windows.Forms.HtmlElement btn_Submit = this.webBrowser1.Document.GetElementById("Submit按钮ID错了,只有close_button没有Submit"); //点击关闭按钮,这个括号中的submit需要改成什么吗? 
                btn_Submit.InvokeMember("click"); //让我使用new关键字设置实例,该如何设置?? 
    你执行他的onclick方法,但是上面说了,他的代码是在父页面里的你干脆在webbrowser里把他的父页面一起载入算了
      

  14.   

    这个子页面貌似就是个SWF,关闭后就没了,回到父页面
      

  15.   

    直接执行onclick里的js应该是对的,少了个parent,是调用父窗口的closeResult  string scripts ="window.parent.closeResult();"; 
    IHTMLWindow2 win = (IHTMLWindow2)webBrowser1.Document.Window.DomWindow; 
    win.execScript(scripts, "Javascript");