在ajax之后更新webBrowser html [英] Update webBrowser html after ajax

查看:66
本文介绍了在ajax之后更新webBrowser html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过AJAX函数更新后,我需要获取webBrowser的更新html

I need to get the updated html of webBrowser after it gets updated by an AJAX function

例如,我导航至 page1.asp,但导航至 page1 .asp包含一个iframe,该iframe可从另一个页面加载内容。它还具有jQoery功能,可在xx秒后显示提交按钮。

For example, I navigate to "page1.asp", but "page1.asp" includes an iframe that loads content from another page. It also has an jQoery function that display a Submit button after xx seconds.

我的问题是如何从webBrowser获取最新的html?

My question is how can I get the most recent html from webBrowser?

我尝试更新但没有运气,

I tried update but no luck,

webBrowser.Update();


推荐答案

这个问题有点棘手,您需要遵循正确遵循准则以实现您的目标。

Well its a bit tricky question you need to follow the following guidelines correctly in order to achieve your goals.


  1. 您需要在表单上创建一个计时器。用刻度线将其绑定,并给出大约500毫秒的间隔。

  2. 在timer_tick事件中编写以下代码:

  1. you need to create a timer on the form. bind it with tick and give an interval about 500 ms.
  2. write this code in the timer_tick event:

如果(browser.ReadyState == WebBrowserReadyState.Complete)

if (browser.ReadyState == WebBrowserReadyState.Complete)

一旦发现就绪状态已完成,那么您将寻找您认为在ajax请求完成后将被更新的html元素。

Once you find the ready state completed then you look for the html element that you think will be updated after completion of ajax request.

您可以通过以下方式检查任何元素:

You could do this way to check any element:

        HtmlElementCollection forms = browser.Document.GetElementsByTagName("form");
        HtmlElement form = null;
        foreach (HtmlElement el in forms)
        {
            string name = el.GetAttribute("name");
            if (name == "DATA")
            {
                form = el;
                break;
            }
        }

4)一旦有了元素,就可以携带

4) Once you have got your element you may carry on your work.

更新:以下是计时器滴答编码,您可以根据自己的需要进行扩展
确保已设置 Timer1.Inverval = 100 (100毫秒)

Update: Here is the timer tick coding that you can extend as per your needs Make sure you have set your Timer1.Inverval = 100 (100 milli seconds)

    private void Timer1_Tick(sender, args) 
    {
        Application.DoEvents();

// make sure your are pulling right element id
        HtmlElement cTag = webBrowser.Document.GetElementById("myelement");         

        if(cTag != null) // if elemnt is found than its fine. 
        { 
            cTag.SetAttribute("value", "Eugene");
            Timer1.Enabled = false;
        } 
        else 
        {
// dont worry, the ajax request is still in progress... just wait on it and move on for the next tick. 
        }
        Application.DoEvents(); // you can call it at the end too.
    }

这篇关于在ajax之后更新webBrowser html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆