开发者

Silverlight and Javascript interaction

I have a page with a silverlight app on it. Embedded in my page is an authentication key which t开发者_JAVA技巧he 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.


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜