代码如下   为什么webbrowser.document为空?  如何解决?webbrowser.url=new Uri("http://localhost/www/test.htm");
webbrowser.show();
webbrowser.document.invokescript("getInfo");

解决方案 »

  1.   

    不要在load事件里写webbrowser.document.invokescript("getInfo");
      

  2.   


    也就是webbrowser.show()以后不能立即执行webbrowser.document.invokescript("getInfo")?
      

  3.   

    在WinForm下用这个控件会比较好!其它的地方都有或多或少的问题存在,我遇见过!
      

  4.   

    写到DocumentCompleted里就行了,LOAD的时候WEBBROWER还没加载完HTML
      

  5.   

    写发不对吧。你要完成功能是什么那? 参考我的代码
     private void button1_Click(object sender, EventArgs e)
            {
                object Zero = 0;
                object EmptyString = "";
                axWebBrowser1.Navigate(textBox1.Text, ref Zero, ref EmptyString, ref EmptyString, ref EmptyString);
            }        private void axWebBrowser1_DocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
            {
                IHTMLDocument2 HTMLDocument = (IHTMLDocument2)axWebBrowser1.Document;
                IHTMLElementCollection links = HTMLDocument.links;            listBox1.Items.Clear();
                string uspath = Application.StartupPath + "\\WriteLines.html";
                uspath.Remove(0);
                //using ( StreamWriter sw = new StreamWriter(@"C:\WriteLines.html", true))
                using (StreamWriter sw = new StreamWriter(uspath, true))
                    foreach (HTMLAnchorElementClass el in links)
                    {
                        listBox1.Items.Add(el.outerHTML);
                                           //sw.Close();
                    }                    }