Calling a JavaScript function from Silverlight 2

Wow, this is far better now with SL2! no more tips and tricks.

JavaScript:

<script type="text/javascript">
function DisplayMessage()
{
    alert("call me from Silverlight 2");
}
</script>

Silverlight:

using System.Web.Browser;

HtmlPage.Window.CreateInstance("DisplayMessage");
Published Wednesday, March 26, 2008 5:30 AM by pluginbaby
Filed under:

Comments

Wednesday, March 26, 2008 3:24 AM by Joe Chung

# re: Calling a JavaScript function from Silverlight 2

Can you put an arbitrary function in your CreateInstance call?

HtmlPage.Window.CreateInstance("function() { alert(\"call me from Silverlight 2\"); }");

Thursday, March 27, 2008 5:02 PM by pluginbaby

# re: Calling a JavaScript function from Silverlight 2

For inline functions use this:

HtmlPage.Window.Eval("(function(){ alert('inline Js function call from Silverlight 2'); })()");

Saturday, March 29, 2008 3:27 PM by Laurent Kempé

# re: Calling a JavaScript function from Silverlight 2

Hey Laurent

I started to make a proto for THB comments using this :)

Regards

Laurent

Tuesday, June 17, 2008 1:46 AM by ah

# re: Calling a JavaScript function from Silverlight 2

pls I cant find

using System.Web.Browser;

Thursday, June 19, 2008 11:12 PM by pluginbaby

# re: Calling a JavaScript function from Silverlight 2

@ah: if you use VB you need to write "Imports System.Web.Browser"