Lately, I have ran into the problem with not being able to inject javascript through a webbrowser contol without writing to a new html. Is there a way to inject a string of javascript to the currently browsed webpage?
javascript:(function(){var s=document.createElement('script');s.setAttribute('src','file:///C:/abc.js');document.getElementsByTagName('head')[0].appendChild(s);})()
The current method I am using involves stringbuilder and webbrowser w/ windows.forms.document
string js = @"<script type='text/javascript'>function test(){alert(test)}</script>";
WebBrowser wb = new WebBrowser();
wb.Url = new Uri("http://www.google.com");
wb.Document.Write(js);
wb.Document.InvokeScript("test");
What am I doing wrong? Is there a better working way of approaching this?