+ Reply to Thread
Results 1 to 2 of 2

Thread: Parsing Information from Windows Form to JavaScript Function

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    28

    Parsing Information from Windows Form to JavaScript Function

    hey , today while working i was asked to provide a function on the application that has some kind of information lets say some text and a javascript function should call that function inside application and read the information inside it .

    By the way there is a web browser control inside the application.

    Any idea how can i do that ?
    Last edited by rady; 11-07-2012 at 10:13 PM.

  2. #2
    Junior Member
    Join Date
    May 2012
    Posts
    36
    Inside application :
    Code:
    using System.Runtime.InteropServices;
    Code:
    [System.Runtime.InteropServices.ComVisibleAttribute(true)]
    
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
    
            public IFoo CreateFoo()
            {
                return new Foo() { Bar = "somevalue" };
            }
    
            public string Bar(IFoo foo)
            {
                return foo.Bar;
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                webBrowser1.ObjectForScripting = this;
            }
    
        }
        [ComVisible(true)]
        public interface IFoo
        {
            string Bar { get; set; }
        }
        [ComVisible(true)]
        public class Foo : IFoo
        {
            public string Bar { get; set; }
        }
    Okay lets head to the JavaScript Function :
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    
    <script type="text/javascript" language="javascript" >
    
    function Callme(){
    	var foo = external.CreateFoo();
    	alert(foo.Bar);
    	alert(external.Bar(foo));
    }
    </script>
    
    </head>
    
    <body>
    
    <button title="Press me ;)" value="Press me ;)" onclick="Callme()" >Press me ;)</button>
    
    </body>
    </html>

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts