c# webBrowser 获取Ajax信息

   c#中 webbrowser控件对Ajax的执行,没有任何的响应,难于判断Ajax是否已经执行完毕,我GG了一下午,找到一个方法,介绍一下:

  假如在页面中有个<div id=result></div>是通过Ajax来改变值,当webBrowser1.StatusText == "完成"后,获取一下这个div

HtmlElement target = webBrowser1.Document.GetElementById("result");

  先判断一下,再添加响应函数

                                if (target != null)
                                {
                                    target.AttachEventHandler("onpropertychange", new EventHandler(handler));
                                }

其中handler为响应函数名称。

        private void handler(Object sender, EventArgs e)
        {
            HtmlElement div = webBrowser1.Document.GetElementById("result");
            if (div == null) return;
            String x = div.InnerHtml; // etc
            if (!x.Equals("Loading...", StringComparison.InvariantCultureIgnoreCase))
            {
                // Now the element has been populated, do something
            }
        }

猜你喜欢

转载自blog.csdn.net/sql2zy/article/details/5645315
今日推荐