The following steps shows how to call a Javascript method from Silverlight.
Open the ASP.NET or HTML page which hosts the Silverlight control. Add the Javascript method as shown below:
<script language="javascript"&Gt;
function SayHello()
{
alert("Hello from JavaScript, invoked by Silverlight");
}
</script>
Now, open your XAML control file and add a button control as shown below:
<Grid x:Name="LayoutRoot" Background="White">
<Button x:Name="btnSayHello" Content="Say Hello"
Click="btnSayHello_Click"></Button>
</Grid>
Go to the code behind file for the XAML Page and add the event handler for the button click event:
private void btnSayHello_Click(object sender, RoutedEventArgs e)
{
HtmlPage.Window.Invoke("SayHello");
}
In order to use the HtmlPage class, you need to include the System.Windows.Browser
using System.Windows.Browser;
You are done. Run your Silverlight application and see. When you click on the button in the Silverlight control, you can see the popup message from the Javascript function.