Logo
My Account |  Site Map | Contact Us  

Accessing .NET Code from JavaScript Code with EO.WebBrowser

All Products
EO.Web Controls
EO.Pdf for .NET
EO.Wpf for .NET
EO.WebBrowser for .NET
For Win Forms App
For WPF Apps
Custom Context Menu
.NET -> JavaScript
JavaScript -> .NET
Resource Handler
TabbedBrowser Sample
EO.WebBrowser also supports "JavaScript Extension", which allows you to register a .NET function as a JavaScript function, thus allowing JavaScript code to call .NET code. The following code creates a JavaScript function "demoAbout":
C# VB.NET  
//Register extension function "demoAbout"
webView1.RegisterJSExtensionFunction("demoAbout", new JSExtInvokeHandler(WebView_JSDemoAbout))

//Extension handler function
void WebView_JSDemoAbout(object sender, JSExtInvokeArgs e)
{
    string browserEngine = e.Arguments[0] as string;
    string url = e.Arguments[1] as string;
    MessageBox.Show("Browser Engine: " + browserEngine + ", Url:" + url);
}

After the above code, you can call "demoAbout" directly from your JavaScript code:

JavaScript  
//This code will call WebView_JSDemoAbout 
demoAbout(window.navigator.appVersion, document.URL);

The above code calls the .NET WebView_JSDemoAbout function. The two arguments passed to the JavaScript function are also passed to the .NET side available through the .NET event argument object.

See here for detailed information on how to call .NET code from JavaScript code.

Additional Resources

  • Product Documentation

    All features are explained in great details in the product documentation. It also contains complete reference information for each type, property or method;

  • Samples

    The download package contains a wide variety of samples with full C# and Visual Basic.NET source code that demonstrate how to use different feature of the EO.WebBrowser library.

  • Technical Support

    Still have questions? Post in our support forum or contact us and we will answer them quickly. Our turn around time is among the best in the industry.