How to inject Javascript in WebBrowser control?

前端 未结 15 2263
夕颜
夕颜 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:53

    If all you really want is to run javascript, this would be easiest (VB .Net):

    MyWebBrowser.Navigate("javascript:function foo(){alert('hello');}foo();")
    

    I guess that this wouldn't "inject" it but it'll run your function, if that's what you're after. (Just in case you've over-complicated the problem.) And if you can figure out how to inject in javascript, put that into the body of the function "foo" and let the javascript do the injection for you.

提交回复
热议问题