C#Webbrowser控件 - 定义加载的文档

时间:2010-04-15 14:17:38

标签: browser webbrowser-control

DocumentCompleted将在加载所有dom元素(图像,flash等)后工作。我正在等待所有dom元素下载到本文档。如何定义何时加载documnet(页面)(当客户端看到页面时)?是否有任何事件要定义何时将文件加载到客户端?

1 个答案:

答案 0 :(得分:1)

为什么不让页面举起活动?例如,像:

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.");
        }
    }
}

在上面的示例中,页面使用 onLoad()事件在页面加载完成后通知表单。

希望这有帮助。

相关问题