???????????????£?
????==============================================================================
????JS???????
????<script language=”javascript”>
????function jsAlert(infor)
????{
????alert(‘?????????Я????????????????????????????’);
????return;
????}
????</script>
????C#??????????£?
????using System.Security.Permissions;
????[PermissionSet(SecurityAction.Demand?? Name = "FullTrust")]//??????? ???????????????????У????????????
????[System.Runtime.InteropServices.ComVisibleAttribute(true)]
??????????????
????webBrowser1.Document.InvokeScript("jsAlert "?? new string[] {‘ssss’});
????JS?е???C#?????????
????C#???????£?
????public void ShowMessage(string message)
????{
????MessageBox.Show(message);
????}
????JS?????÷?????
????<script language=”javascript”>
????function InvokeFunc()
????{
????window.external.ShowMessage(‘???’);
????}
????</script>
?????????C#????winform????????У??????????????????????WebBrowser?????????????????????????????????????????????????????????????е????JS????????????????п?????????????ó????е??????????Щ??????????????????????λ?????н?????
????===========================================================================================================
????????????c# ???????js???漲??? ???????????
JScript code
<script language="javascript"type="text/javascript">
varg_h=55;
functiondisplayVar(varname)
{
try
{
returneval(varname);
}
catch(e)
{
returne.description;
}
}
</script>
????c#????????????g_h??????????????????????????
??????????????????????????????eval??????????????μ????????????????????g_h
????C# code
????object[] paramArray=newobject[1];
????paramArray[0]="g_h";
????webBrowser1.Document.InvokeScript("displayVar"?? paramArray);
??????????????????????
????webBrowser1.Document.InvokeScript("JS??????"?? New Object() {????})
???????????:????????÷?”??“???? ??
???????磺
????webBrowser1.Document.InvokeScript("Go"?? New Object() {"home"??"back"})
????+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
???????????????
??????Case 1???У??????????????Web????HTML???????????????Windows Form???????????????????????????Web??????WinForm?????????
????????WinForm?????????????Web????HTML????????????Web?????????Script???
?????????????Web??????????????????????????HTML????????Javascript??
????function DoAdd(a?? b) {
????return a + b;
????}
????????????????WinForm??????????????′??????
????object oSum = webBrowser.Document.InvokeScript("DoAdd"?? new object[] { 1?? 2 });
????int sum = Convert.ToInt32(oSum);
??????Σ????????????????Web??????????е??????????????????.Net??????????????????????COM???IHTMLWindow2?????????????????????????????С?
string scriptline01 = @"function ShowPageInfo() {";
string scriptline02 = @"      var numLinks = document.links.length; ";
string scriptline03 = @"      var numForms = document.forms.length; ";
string scriptline04 = @"      var numImages = document.images.length; ";
string scriptline05 = @"      var numScripts = document.scripts.length; ";
string scriptline06 = @"      alert('???????????? ????????' + numLinks + ";
string scriptline07 = @"         ' ???????' + numForms + ";
string scriptline08 = @"         ' ???????' + numImages + ";
string scriptline09 = @"         ' ???????' + numScripts);}";
string scriptline10 = @"ShowPageInfo();";
string strScript = scriptline01 + scriptline02 + scriptline03 + scriptline04 + scriptline05 +
scriptline06 + scriptline07 + scriptline08 + scriptline09 + scriptline10;
IHTMLWindow2 win = (IHTMLWindow2)webBrowser.Document.Window.DomWindow;
win.execScript(strScript?? "Javascript")