Knowledge:
[C-sharp]
View plaincopyprint?
- [System. runtime. interopservices. comvisibleattribute (True)]
- This is to set this class to com accessible
- URL property: the webpage path displayed by the webbrowser Control
- Objectforscripting property: This object can be accessed by the script code contained in the webpage displayed in the webbrowser control.
- Javascript calls the C # public method through window. External. This is the public method contained in the instance of the class set by the objectforscripting attribute.
- // Web page path displayed by the webbrowser Control
- Webbrowser1.navigate (NewUri (system. environment. currentdirectory + @ "/xxx.html ",
Urikind. relativeorabsolute ));
- // Set the current class to be accessed by a script
- Webbrowser1.objectforscripting =This;
[System. runtime. interopservices. comvisibleattribute (true)] <br/> This is to set this class to com accessible </P> <p> URL attribute: the webpage path displayed by the webbrowser Control </P> <p> objectforscripting attribute: This object can be accessed by the script code contained in the webpage displayed in the webbrowser control. <br/> JavaScript uses window. external calls the C # public method. This is the public method contained in the instance of the class set by the objectforscripting attribute. </P> <p> // web page path displayed by the webbrowser Control <br/> webbrowser1.navigate (New uri (system. environment. currentdirectory + @ "/xxx.html", urikind. relativeorabsolute); <br/> // set the current class to be accessed by a script <br/> webbrowser1.objectforscripting = This; <br/>
. CS
[C-sharp]
View plaincopyprint?
- UsingSystem;
- UsingSystem. Collections. Generic;
- UsingSystem. LINQ;
- UsingSystem. text;
- UsingSystem. windows;
- UsingSystem. Windows. controls;
- UsingSystem. Windows. Data;
- UsingSystem. Windows. documents;
- UsingSystem. Windows. input;
- UsingSystem. Windows. Media;
- UsingSystem. Windows. Media. imaging;
- UsingSystem. Windows. Navigation;
- UsingSystem. Windows. shapes;
- UsingSystem. Web;
- UsingSystem. Security. permissions;
- NamespaceWpfapplication1
- {
- /// <Summary>
- /// Interaction logic for window1.xaml
- /// </Summary>
- PublicPartial
ClassWindow1: Window
- {
- PublicWindow1 ()
- {
- Initializecomponent ();
- Basic DS =NewBasic ();
- Webbrowser1.navigate (NewUri (system. environment. currentdirectory + @ "/aaa.html ",
Urikind. relativeorabsolute); // obtain the calendar file in the root directory
- Webbrowser1.objectforscripting = Ds; // This object can be accessed by the script code contained in the webpage displayed in the webbrowser control.
- }
- Private
VoidButton_click (ObjectSender, routedeventargs E)
- {
- Textbox1.text = dosomething. Name;
- }
- }
- [System. runtime. interopservices. comvisibleattribute (True)] // Set this class to com accessible
- Public
ClassBasic
- {
- Public
Static
StringName;
- Public
StringName
- {
- Get{
ReturnName ;}
- Set{Name = value ;}
- }
- Public
VoidClickevent (StringStr)
- {
- This. Name = STR;
- }
- }
- }
Using system; <br/> using system. collections. generic; <br/> using system. LINQ; <br/> using system. text; <br/> using system. windows; <br/> using system. windows. controls; <br/> using system. windows. data; <br/> using system. windows. documents; <br/> using system. windows. input; <br/> using system. windows. media; <br/> using system. windows. media. imaging; <br/> using system. windows. navigation; <br/> using system. windows. shapes; <br/> using system. web; <br/> using system. security. permissions; <br/> namespace wpfapplication1 <br/> {<br/> /// <summary> <br/> // interaction logic for window1.xaml <br/> // </Summary> <br/> Public partial class window1: window <br/>{< br/> Public window1 () <br/>{< br/> initializecomponent (); <br/> basic DS = new basic (); <br/> webbrowser1.navigate (New uri (system. environment. currentdirectory + @ "/aaa.html", urikind. relativeorabsolute); // obtain the calendar file of the root directory <br/> webbrowser1.objectforscripting = Ds; // This object can be accessed by the script code contained in the webpage displayed in the webbrowser Control <br/>}< br/> private void button_click (Object sender, routedeventargs E) <br/>{< br/> textbox1.text = dosomething. name; <br/>}</P> <p >}< br/> [system. runtime. interopservices. comvisibleattribute (true)] // set this class to com accessible <br/> public class basic <br/>{< br/> Public static string name; <br/> Public string name <br/>{< br/> get {return name ;}< br/> set {name = value ;} <br/>}< br/> Public void clickevent (string Str) <br/>{< br/> This. name = STR; <br/>}< br/>
Html
[C-sharp]
View plaincopyprint?
- <HTML>
- <Head>
- <MCE: script language = "JavaScript" type = "text/JavaScript"> <! --
- Function selec ()
- {
- VaR divv = Document. getelementbyid ('div2'). innertext;
- Window. External. clickevent (divv );
- }
- // --> </MCE: SCRIPT>
- </Head>
- <Body>
- <Form>
- <Div id = "div1" onclick = "selec ();"> 000000000000 </div>
- <Div id = "div2"> 111111 </div>
- </Form>
- </Body>
- </Html>
<HTML> <br/> <pead> <br/> <MCE: script language = "JavaScript" type = "text/JavaScript"> <! -- <Br/> function selec () <br/> {<br/> var divv = document. getelementbyid ('div2 '). innertext; <br/> window. external. clickevent (divv); <br/>}< br/> // --> </MCE: SCRIPT> <br/> </pead> <br/> <body> <br/> <form> <br/> <Div id = "div1" onclick = "selec (); "> 000000000000 </div> <br/> <Div id =" div2 "> 111111 </div> <br/> </form> <br/> </body> <br/> </ptml>
If you need to click the button during running and then pass the value to the page for display, use the following method to pass the value
This. Webbrowser1.invokescript ("functions in JS", "values to be passed ");