C # Web Browser Management - Detecting a loaded document

DocumentCompleted will work after loading all dom elements (images, flash, etc.). And I'm waiting for all dom elements to load to work on this document. How to determine when a documnet (page) is loaded (when the client sees the page)? Is there any event to determine when a document is LOADED to a client?

+3
source share
1 answer

Why not let the page create an event? For example, 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 example, the page uses the onLoad () event to notify the form when the page has finished loading.

Hope this helps.

+1

Source: https://habr.com/ru/post/1741280/


All Articles