开发者

Javascript is crashing when trying to access silverlight content

开发者 https://www.devze.com 2022-12-08 02:40 出处:网络
I have a web application containing a silverlight control. When the specific page is accessed that contains the silverlight control a javascript is executed and if this script is executed too early, t

I have a web application containing a silverlight control. When the specific page is accessed that contains the silverlight control a javascript is executed and if this script is executed too early, the script crashes the javascript engine in IE, not even a try/catc开发者_运维问答h can handle the error.

Simple javascript

silverlightHtmlElement.Content.SilverlightApplication.SilverlightMethod();

If the silverlight control element hasn't been fully loaded the script crashes, and not only the script, no further javascript is executed on the page at all.

A simple "if (silverlightHtmlElement.Content.SilverlightApplication)" to check if the its accessible is enough for a crash.

The problem is that I can't execute the script later on the page. Anyone else seen this before?


you need to make sure that the code is not executed until the control is active/loaded, add this param to your silverlight object tag:

<param name="onLoad" value="pluginLoaded" />

then define a javascript function on the page like this

var app= null;
function pluginLoaded(sender, args) {
    app= sender.getHost();
}

then you can just add your call to the method to the loaded event handler or query the app variable for null to see if its ready.


You could write some Silverlight code that executes a javascript function after it has finished initalizing. This way your silverlight app can notify the web page when it has finished loading.

HtmlPage.Window.Invoke("myJsFunction", null);
0

精彩评论

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