How to inject Javascript in WebBrowser control?

前端 未结 15 2655
夕颜
夕颜 2020-11-22 04:56

I\'ve tried this:

string newScript = textBox1.Text;
HtmlElement head = browserCtrl.Document.GetElementsByTagName(\"head\")[0];
HtmlElement scriptEl = browser         


        
15条回答
  •  我寻月下人不归
    2020-11-22 05:37

    What you want to do is use Page.RegisterStartupScript(key, script) :

    See here for more details: http://msdn.microsoft.com/en-us/library/aa478975.aspx

    What you basically do is build your javascript string, pass it to that method and give it a unique id( in case you try to register it twice on a page.)

    EDIT: This is what you call trigger happy. Feel free to down it. :)

提交回复
热议问题