开发者

C# Webbrowser control - Defining document loaded

DocumentCompleted will work after all dom elements loaded (images, flash and etc.). And I am waiting when all dom elements are downloaded to work this document. How can I define when documnet (page) loaded (when client see the page)? Is there any event to define when document LOAD开发者_开发知识库ED to client?


Why not let the page raise an event? For instance, something like:

using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace TestWebBrowser
{
    [ComVisible(true)]
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, System.EventArgs e)
        {
              webBrowser1.ObjectForScripting = this;
              webBrowser1.DocumentText = @"
                    <html>
                    <body onLoad='jscript:window.external.DocumentLoaded();'>
<img src=""http://www.nasa.gov/images/content/464377main_image_1695_1600-1200.jpg"" />
</body>
</html>";
        }

        public void DocumentLoaded()
        {
            MessageBox.Show("Document Finished Loading.");
        }
    }
}

In the above sample the page uses the onLoad() event to notify the form when the page has finished loading.

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜