WebBrowser InvokeScript

I have a Webrowser with some settings that change using javascript. I am trying to use an example here , but cannot get the correct syntax

the script is as follows

        <div class="DisplayInput"><input type="radio" name="displaytype" 
value="decimal" onclick="setdisplayType('decimal');" checked="checked"><a 
    href="javaScript:setdisplayType('decimal');" 
    onclick="s_objectID=&quot;javascript:setdisplayType('decimal');_1&quot;;return this.s_oc?     this.s_oc(e):true">Decimal</a></div>

So far I tried this without success

this.webBrowser1.InvokeScript("setdisplayType");
this.webBrowser1.InvokeScript("setdisplayType('decimal')");
this.webBrowser1.InvokeScript("setdisplayType","decimal");
+3
source share
3 answers

Not knowing what is happening with your application error, and also not knowing what it looks like setdisplayType, I assume that you might be trying to call a function setdisplayTypebefore loading it. In the MSDN documentation ...

InvokeScript (String, Object()) , , . , , LoadCompleted.

, LoadCompleted, script.

, !

+7

. :

Object[] parameters = new Object[1]; //assuming your JS function has one parameter
parameters[0] = (Object)"yourStringParameter"; //for example the parameter is a string
yourBrowser.Document.InvokeScript("scriptName", parameters);
+1

:

private async void web_LoadCompleted(object sender, NavigationEventArgs e)
{
  Object[] parameters = new Object[1]; 
  await yourBrowser.Document.InvokeScript("scriptName", parameters);
}
0

All Articles