Developing winform using C # Program During the process, we often encounter browser controls embedded with a webbrowser. In many cases, we need to control the webpage display mode in the program, or call a JS function in the webpage. In turn, it is also possible that the webpage also needs to call functions in the program to implement some functions. Next I will explain how to interact with each other.
The JS script called by the program is as follows:
JS script Code :
<Script language = "JavaScript">
Function shopxg (INFOR)
{
Alert ('I want to open an online shop and buy an independent online shop system with the most complete template and the most professional system! ');
Return;
}
</SCRIPT>
C # The code is called as follows:
UsingSystem. Security. permissions;
Note: The following two lines must be added before the class definition; otherwise, the call fails!
[Permissionset (securityaction. Demand, name ="Fulltrust")]
[System. runtime. interopservices. comvisibleattribute (True)]
Called functions:
Webbrowser1.document. invokescript ("Shopxg",New String[] {'Sss '});
Example of Calling C # functions in JS:
C # functions:
Public VoidShowmessage (StringMessage)
{
MessageBox. Show ("open an online shop for free and invite you to join the independent online shop system with purchase !");
}
Method of calling in JS:
<Script language = "JavaScript">
Function invokefunc ()
{
Window. External. showmessage ('H ');
}
</SCRIPT>
When developing a winform program using C #, we often encounter browser controls embedded with a webbrowser. In many cases, we need to control the webpage display mode in the program, or call a JS function in the webpage. In turn, it is also possible that the webpage also needs to call functions in the program to implement some functions. Next I will explain how to interact with each other.
The JS script called by the program is as follows:
JS script code:
<Script language = "JavaScript">
Function shopxg (INFOR)
{
Alert ('I want to open an online shop and buy an independent online shop system with the most complete template and the most professional system! ');
Return;
}
</SCRIPT>
C # The code is called as follows:
UsingSystem. Security. permissions;
Note: The following two lines must be added before the class definition; otherwise, the call fails!
[Permissionset (securityaction. Demand, name ="Fulltrust")]
[System. runtime. interopservices. comvisibleattribute (True)]
Called functions:
Webbrowser1.document. invokescript ("Shopxg",New String[] {'Sss '});
example of Calling C # function in JS:
C # function:
Public void showmessage ( string message)
{< br> MessageBox. show! ");
}< br> call method in JS: