A question about intercommunication between Silverlight and the HTML host has been asked in the Israeli MSDN forum.
Since I’ve already implemented it once in a project, I believe I can extract the great info already exist in the MSDN documentation to a more direct how-to.
Let’s begin.
- Create a class called JavaScriptBridge
- Each method that you would like to be exposed to the HTML host, thus be possible to get called by JavaScript you adorn with [ScriptableMember] attribute.
[ScriptableMember()]
public void DoSomething(int a, int b)
{
}
- Inside the App.xaml.cs, on the Application_startup event handler, register the an instance of the bridge
private void Application_Startup(object sender, StartupEventArgs e)
{
this.RootVisual = new MainPage();
JavaScriptBridge javaScriptBridge = new JavaScriptBridge();
HtmlPage.RegisterScriptableObject("bridge", javaScriptBridge);
}
- We are done with Silverlight side, now we move on to the HTML host, locate the aspx file (usually) that contains the Silverlight object. In this page you will notice that it is represented as an <object> tag. Insert an event handler for the onLoad event of the object.
<param name="onLoad" value="pluginLoaded" />
-
Also add an input button for testing the interface.
<input id="Button1" type="button" value="Test"
onclick="test()" />
-
Implement both event handlers:
var silverlight = null;
function pluginLoaded(sender, args) {
silverlight = sender.getHost();
}
function test() {
if (silverlight != null) {
silverlight.Content.bridge.DoSomething(10, 10);
}
}
-
Hopefully, now we look back and appreciate how easy it is to mix those two worlds

Ariel