我想确定访问silverlight Web应用程序的客户端是否安装了silverlight运行时,如果不是,我想重定向到显示无法运行应用程序的原因的aspx页面(而不是消息框告诉缺少silverlight插件)。怎么做?
答案 0 :(得分:1)
此Javascript提供警告我确信可以将其更改为重定向用户
function hasSilverlightPlugin() {
var slplugin = false;
var browser = navigator.appName; // Get the browser type
if (browser == 'Microsoft Internet Explorer') {
try {
var slControl = new ActiveXObject('AgControl.AgControl');
if (slControl) {
slplugin = true;
}
} catch (e) { }
}
else {
// Netscape, FireFox, Google chrome etc
try {
if (navigator.plugins["Silverlight Plug-In"]) {
slplugin = true;
}
} catch (e) { }
}
return slplugin;
}
/** This function checks the browser to see if Silverlight has been installed.
* The display informing the user that his/her browser is lacking the plugin
* is shown in the Announcements section of the desktop tab.
*/
function silverlightAnnouncementWarning() {
var elem = null;
var hasPlugin = hasSilverlightPlugin();
elem = document.getElementById("SilverlightWaringElem");
if (!hasPlugin) {
if (elem) {
elem.style.display = "";
var warningMsg = "WARNING THE SILVERLIGHT PLUGIN IS NOT INSTALLED ON THIS MACHINE"
elem.innerHTML = warningMsg;
}
}
//64 bit silverlight warning
if (navigator.platform == "Win64") {
if (elem) {
var warningMsg = "64 bit browser has been detected which is currently incompatible with Silverlight"
elem.style.display = "";
var msg = elem.innerHTML;
if (msg && msg.length > 0) {
warningMsg = msg + " (also a " + warningMsg + ")";
} else {
warningMsg = "A " + warningMsg;
}
elem.innerHTML = warningMsg;
}
}
}
function popupSilverlightWarning() {
var hasPlugin = hasSilverlightPlugin();
if (!hasPlugin) {
var warningMsg = "THE SILVERLIGHT PLUGIN IS NOT INSTALLED ON THIS MACHINE!\n";
warningMsg += "This page requires the Silverlight plugin in order to work.\n";
warningMsg += "Please contact your Systems Administrator to have the Silverlight plugin installed on this computer.\n";
warningMsg += "Thank you . . .";
alert(warningMsg);
}
}
答案 1 :(得分:0)
上面的JavaScript很不错,但是Silverlight 4.0有一个很好的JavaScript file,每个项目都可以让这类东西变得更容易。
http://msdn.microsoft.com/en-us/library/cc265155(vs.95).aspx