Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silverlight and Javascript interaction

I have a page with a silverlight app on it. Embedded in my page is an authentication key which the silverlight app will need to do all web service requests. So onload the silverlight app needs to get the key and do an initial connect to a WCF service. The problem is that its very unpredictable whether the page or the silverlight will load first, so I cant use the pages onload= event because sometimes the silverlight is null, and I cant use silverlights initialize method because sometimes the js function is still undefined - which I presume means its loading the page from cache, which loads the SL, and only then parsing the JS.

Thanks.

like image 886
Matt Avatar asked Nov 14 '22 07:11

Matt


1 Answers

You can get Silverlight interop to invoke a JS method and get its return value using the following:

// Returning a String
string stringValue = (string)HtmlPage.Window.Invoke("myJSMethod"); 

where myJSMethod returns the embedded key. But if you're embedding the key anyway, why not just put in into the <object><param>s?

<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
  <param name="myKey" value="myKeyValue"/>
  ...
</object>
like image 156
grav3nimag3 Avatar answered Nov 17 '22 05:11

grav3nimag3