简体   繁体   English

在这种情况下如何从C#调用WebBrowser控件中的JavaScript

[英]how to Calling JavaScript in a WebBrowser control from C# in such a situation

sorry, my poor English,my question is as following: 抱歉,我的英语不好,我的问题如下:

Calling JavaScript in a WebBrowser control from C# in ordinary way: JavaScript 以普通方式从C#在WebBrowser控件中调用JavaScript:JavaScript

function showMe()

{ ... } {...}

C# C#

webBrowser1.Document.InvokeScript("showMe");

that is ok! 那没问题!

but how to call in such situation: 但是在这种情况下如何呼叫:

html: HTML:

<a href="javascript:void(0);" onclick="App.followcancel('1880161672',this,'0','A','B');return false;">hello</a>

c#: C#:

webBrowser1.Document.InvokeScript(????????)

I don't know how to write the correct paremeter to achieve the onclick's javascript 我不知道如何编写正确的参数来实现onclick的javascript

anyone help me,thanks a lot 有人帮助我,非常感谢

Something like this (if you set id of the link to "mylink"): 这样的事情(如果您将链接的ID设置为“ mylink”):

HtmlElement el = webBrowser1.Document.All["mylink"];
object obj = el.DomElement;
System.Reflection.MethodInfo mi = obj.GetType().GetMethod("onclick");
mi.Invoke(obj, new object[0]); 

Following the example you've given: 按照您给出的示例:

webBrowser1.Document.InvokeScript("App.followcancel('1880161672',this,'0','A','B')");

Edit: This example is broken. 编辑:这个例子坏了。

You would need to replace 'this' with document.getElementById('mylink') (assuming an id attribute is set with the value mylink ) or use the approach given by HABJAN. 您可能需要用document.getElementById('mylink')替换'this'(假设id属性设置为值mylink )或使用HABJAN给出的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM