How to execute custom JavaScript in WebBrowser con

2019-01-23 08:20发布

问题:

This question already has an answer here:

  • How to inject Javascript in WebBrowser control? 15 answers

I want to apply some styling commands to specific website inside WebBrowser control. The best way to do it is to invoke javascript (I want that style to be editable, with javascript it's easy). I know I can do it with webBrowser1.Navigate("javascript: alert('hi'); void(0);"); but maximum url length that webBrowser accepts is 502. How to execute longer scripts? Or maybe there is a way to append my CSS to web document?

P.S. I can't edit document's text property since it'll break scripts in this website and I need working copy but just slyled a bit.

回答1:

maybe WebBrowser0.Object.Document.parentWindow.Eval("alert('hello')");