views:

91

answers:

2

How to check if a javascript function exists from silverlight

A: 

Use the HTML Bridge.

If you call HtmlPage.Window.Invoke(); on a javascript method that is not present, the Invoke() call should throw an exception.

Dave Swersky
In the javascript
zachary
+2  A: 

In your silverlight code you check for the presence of anything including a function a with the GetProperty method:-

 var fn = HtmlPage.Window.GetProperty("myJavascriptFunction");
 if (fn != null)
     fn.InvokeSelf("Hello");

On caveat though, if the name exists but it isn't a function the above code will throw an exception.

AnthonyWJones