WebBrowser InvokeScript
我有一个Webrowser,其中包含一些使用javascript更改的设置。 我正在尝试使用此处的示例,但无法获得正确的语法
脚本看起来像这样
到目前为止,我已经尝试过这些并没有成功
this.webBrowser1.InvokeScript("setdisplayType"); this.webBrowser1.InvokeScript("setdisplayType('decimal')"); this.webBrowser1.InvokeScript("setdisplayType","decimal");
不知道你的应用程序的错误发生了什么,也不知道setdisplayType
是什么样的,我猜你可能在加载之前尝试调用setdisplayType
函数。 根据MSDN文档……
在实现加载的文档完成加载之前,不应调用InvokeScript(String,Object())。 您可以通过处理LoadCompleted事件来检测文档何时完成加载。
也许你可以实现LoadCompleted
事件处理程序,然后调用你的脚本。
希望这可以帮助!
您必须传递一个Object数组作为第二个参数。 你可以这样做:
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);
试试这个:
private async void web_LoadCompleted(object sender, NavigationEventArgs e) { Object[] parameters = new Object[1]; await yourBrowser.Document.InvokeScript("scriptName", parameters); }