webbrowser在html中寫入內容並新增js

滄海一滴發表於2013-09-10

在html中寫入內容,並新增js

        private void btnTestJs_Click(object sender, EventArgs e)
        {
            this.webBrowser1.Navigate("about:blank");
            this.webBrowser1.Document.Write("testBody");//make the this.webBrowser1.Document.Body is not null             
            HtmlElement he = this.webBrowser1.Document.CreateElement("script");
            he.SetAttribute("type","text/javascript");
            he.SetAttribute("text","alert('test');");
            this.webBrowser1.Document.Body.AppendChild(he);//add element

        }

相關文章