c#调用Webbrowser中的js方法


第一种:
JS:

<script type="text/javascript"> 
function temp(obj) 
{ 
        document.all["Country"].innerText=obj; 
} 
</script> 

form:

mshtml.IHTMLDocument2 currentDoc = (mshtml.IHTMLDocument2)  webBrowser1.Document.DomDocument; 
mshtml.IHTMLWindow2 win = (mshtml.IHTMLWindow2)currentDoc.parentWindow; 
win.execScript("temp('fdsafadsf)", "javascript");//调用函数temp

第二种:
form:

string[] args = new string[1];
    args[0] = "test";
    //Test为JS里带参数的方法
    webBrowser1.Document.InvokeScript("Test", args);
        //webBrowser1.Document.InvokeScript("Test1");    //没有参数的方法

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

验证码 * Time limit is exhausted. Please reload CAPTCHA.