webbrowser在html中写入内容并添加js

在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

        }
posted @ 2013-09-10 10:10  沧海一滴  阅读(1869)  评论(0编辑  收藏  举报