下面是打开包含silverlight控件的对话框的代码
$('#ReadCard').on('click', function (e) {
$('#silverlightControlHost').height('300');
e.preventDefault();
//show the read card dialog
$("#readCardDialog").dialog({
autoOpen: true,
height: 390,
width: 550,
modal: true,
resizable: false,
buttons: {
'Close': function () {
Call_SL_OnBeforeUnload();
$(this).dialog("close");
}
}
});
});
在加载 silverlight 控件时,会调用 SilverlightInitialisation 的方法:
function onSilverlightLoad(sender, eventargs) {
.....
pluginElem.Content.SR_SMT.SilverlightInitialisation(inputArray);
}
由可选的 silverlight 参数调用:
<param name="onload" value="onSilverlightLoad" />
这启动了 silverlight 控件正在与之通信的硬件。
当对话框关闭时,调用该方法来停止硬件:
Call_SL_OnBeforeUnload();
但是,当对话框再次在 IE 中显示时,SilverlightInitialisation 方法永远不会被调用,除非用户刷新页面。
解决方法是将方法 (OnLoad) 更改为在打开对话框时始终调用但检查标志 (hasLoaded) 以查看之前是否加载过的 silverlight 控件:
银光
[ScriptableMember]
public string OnLoad()
{
string retVal = G4T.SilverlightBadge.Resources.ResourcesFile.Present_Card;
if (_badgeReadCtrl != null && hasLoaded)
{
if (!_badgeReadCtrl.Initialise())
{
retVal = "Failed to initialise reader device";
}
}
return retVal;
}
添加了 OnFirstLoad 方法,该方法在 silverlight 控件首次加载并相应地设置标志时调用
[ScriptableMember]
public string OnFirstLoad()
{
string retVal = G4T.SilverlightBadge.Resources.ResourcesFile.Present_Card;
if (_badgeReadCtrl != null)
{
if (!_badgeReadCtrl.Initialise())
{
retVal = "Failed to initialise reader device";
}
}
hasLoaded = true;
return retVal;
}
Javascript
open: function (event, ui) {
try {
var plugin = document.getElementById('SilverlightMainControl');
if (plugin) {
plugin.Content.SR_SMT.OnLoad();
}
}
catch(e){}
},
就像我上面说的,这在 Chrome 中总是可以在没有修改的情况下工作,但在 IE 中,初始化永远不会被多次调用
希望这一切都有意义 - 但我必须记录下来以备将来参考