I’m calling out to javascript from a SL component using the HtmlPage.Window.Invoke api, when I call a javascript function defined in the page (html) it executes as expected, e.g.
HtmlPage.Window.Invoke("publishValue", topic, jsonObject);
But when I place the javascript function in a *.js file it is failing to execute the method even though the *.js file has been loaded into the DOM, so the following fails with an invoke exception.
HtmlPage.Window.Invoke("FrameworkEventBroker.publishFrameworkEvent", topic, jsonObject);
Any ideas why this is happening?
Cheers
AWC
The problem isn’t with the (*.js), it fails when calling methods not directly attached to the window instance.
A workaround would be to register your methods to the window object. To simplify this I created a JavaScript helper as follows:
Then you simply invoke broker methods as:
That’s it.
Example :
and from silverlight:
UPDATE
I added the createDelegate helper to maintain a reference to the broker instance when called on the window object.