Silverlight 3 onload事件绑定多个实例

发布于 2024-08-04 02:50:18 字数 1605 浏览 2 评论 0原文

我在页面中嵌入了两个 silverlight 实例,如下所示(内容仅简化为相关详细信息):-

<object id="SL1" data="data:application/x-silverlight-2," type="application/x-silverlight-2">
   <param name="source" value="/clientBin/Common.xap"></param>
   <param name="minRuntimeVersion" value="3.0.40624.0"></param>
   <param name="windowless" value="True"></param>
   <param name="onload" value="silverlight_onload"></param>
   <param name="initParams" value="some configuration here"></param>
 </object>

<object id="SL2" data="data:application/x-silverlight-2," type="application/x-silverlight-2">
   <param name="source" value="/clientBin/Common.xap"></param>
   <param name="minRuntimeVersion" value="3.0.40624.0"></param>
   <param name="windowless" value="True"></param>
   <param name="onload" value="silverlight_onload"></param>
   <param name="initParams" value="a different configuration here"></param>
 </object>

正如您所看到的,两个 objects 都指向同一个 xap,但在 initParams 中将具有不同的内容。

但请注意,onload 参数指向相同函数名称。这个问题的这个特定部分是不变的。

在全局级别的 JavaScript 中的其他地方,我有:-

function silverlight_onload(sender, eventargs)
{
  //Magic pixie dust here
}

目标是获取发送者并确定哪个对象元素是事件源。直接的(但对于这个问题来说是不可接受的)答案是使用两个不同的函数。我正在寻找不需要将新函数添加到每个 SL 对象的全局命名空间中的东西。

奖金,荣誉归于任何能告诉我为什么 SL 不能从主机浏览器获得更多帮助并更像其他元素事件(如 onlick)处理 onload 参数的人。例如,要求浏览器 eval("function() {" + onload + "}" 并将返回函数附加到 onload 事件。

I have two silverlight instances embedded in a page like follows (content simplfied to relevant details only):-

<object id="SL1" data="data:application/x-silverlight-2," type="application/x-silverlight-2">
   <param name="source" value="/clientBin/Common.xap"></param>
   <param name="minRuntimeVersion" value="3.0.40624.0"></param>
   <param name="windowless" value="True"></param>
   <param name="onload" value="silverlight_onload"></param>
   <param name="initParams" value="some configuration here"></param>
 </object>

<object id="SL2" data="data:application/x-silverlight-2," type="application/x-silverlight-2">
   <param name="source" value="/clientBin/Common.xap"></param>
   <param name="minRuntimeVersion" value="3.0.40624.0"></param>
   <param name="windowless" value="True"></param>
   <param name="onload" value="silverlight_onload"></param>
   <param name="initParams" value="a different configuration here"></param>
 </object>

As you can see both objects point at the same xap but will have different content in the initParams.

Note, however, that the onload param points to the same function name. This particular part of this question is invariant.

Elsewhere in javascript at the global level I have:-

function silverlight_onload(sender, eventargs)
{
  //Magic pixie dust here
}

The goal is to take the sender and determine which of the object elements is the source of the event. The straight-forward (but for the sake of this question unacceptable) answer would be to use two different functions. I'm look for something that does not require a new function be added to the global namespace per SL object.

Bonus, kudos goes to anyone who can tell me why SL couldn't get a little more assistance from the host browser and handle the onload parameter more like other element events like onlick. For example ask the browser to eval("function() {" + onload + "}" and attach the return function to the onload event.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自我难过 2024-08-11 02:50:18

您的目标是在 javascript 中获取 initparams 然后用它做一些事情吗?如果是这样,您可以这样做:

sender.getHost().InitParams

getHost() 返回实际的插件对象 请参阅 msdn 页面了解更多详细信息。我不知道如何获取对象的 ID,除非将其设置为 initparam。

Is your goal to get the initparams in the javascript and then do something with it? If so you can do:

sender.getHost().InitParams

the getHost() returns the actual plugin object see msdn page for more details. I don't know of a way to get the object's ID unless you set it as an initparam.

眼前雾蒙蒙 2024-08-11 02:50:18

那么您的第一个调用点应该是 silverlight。 js 参考

基本上你的“silverlight_onload”javascript函数将作为发送者获取实际的html对象元素,所以检查它的id是什么,你就会得到我认为你想要的东西。

SL 无法从主机获得更多帮助的原因是 html 对象没有 onload 事件。 对象元素参考。


好吧,因为文档似乎没有反映您的现实离开了从 silverlight 控件本身调用 javascript 方法。只需传入一个 id 作为初始化参数之一即可。

Well your first point of call should be the silverlight.js reference.

Basically your "silverlight_onload" javascript function is going to get as sender the actual html object element, so check what it's id is and you'll have what I think you want.

The reason SL can't get more assistance from the host is that the html object doesn't have an onload event. Object Element reference.


Well since the documentation doesn't seem to reflect reality you're left calling the javascript method from within the silverlight control itself. Just pass in an id as one of the init params.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文