判断客户端是否安装framework
安装 .NET Framework 3.5 后,MSI 会将“.NET CLR”和版本号添加到 UserAgent 字符串中。下面的示例演示一个嵌入到简单的 HTML 页的脚本。该脚本搜索 UserAgent 字符串以确定是否已安装 .NET Framework 3.5,并在搜索结果中显示状态消息。
<HTML>
<HEAD>
<TITLE>Test for the .NET Framework 3.5</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8" />
<SCRIPT LANGUAGE="JavaScript">
<!--
var dotNETRuntimeVersion = "3.5.0.0";
function window::onload()
{
if (HasRuntimeVersion(dotNETRuntimeVersion))
{
result.innerText =
"This machine has the correct version of the .NET Framework 3.5."
}
else
{
result.innerText =
"This machine does not have the correct version of the .NET Framework 3.5." +
" The required version is v" + dotNETRuntimeVersion + ".";
}
result.innerText += "\n\nThis machine's userAgent string is: " +
navigator.userAgent + ".";
}
//
// Retrieve the version from the user agent string and
// compare with the specified version.
//
function HasRuntimeVersion(versionToCheck)
{
var userAgentString =
navigator.userAgent.match(/.NET CLR [0-9.]+/g);
if (userAgentString != null)
{
var i;
for (i = 0; i < userAgentString.length; ++i)
{
if (CompareVersions(GetVersion(versionToCheck),
GetVersion(userAgentString[i])) <= 0)
return true;
}
}
return false;
}
//
// Extract the numeric part of the version string.
//
function GetVersion(versionString)
{
var numericString =
versionString.match(/([0-9]+)\.([0-9]+)\.([0-9]+)/i);
return numericString.slice(1);
}
//
// Compare the 2 version strings by converting them to numeric format.
//
function CompareVersions(version1, version2)
{
for (i = 0; i < version1.length; ++i)
{
var number1 = new Number(version1[i]);
var number2 = new Number(version2[i]);
if (number1 < number2)
return -1;
if (number1 > number2)
return 1;
}
return 0;
}
-->
</SCRIPT>
</HEAD>
<BODY>
<div id="result" />
</BODY>
</HTML>
<HEAD>
<TITLE>Test for the .NET Framework 3.5</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8" />
<SCRIPT LANGUAGE="JavaScript">
<!--
var dotNETRuntimeVersion = "3.5.0.0";
function window::onload()
{
if (HasRuntimeVersion(dotNETRuntimeVersion))
{
result.innerText =
"This machine has the correct version of the .NET Framework 3.5."
}
else
{
result.innerText =
"This machine does not have the correct version of the .NET Framework 3.5." +
" The required version is v" + dotNETRuntimeVersion + ".";
}
result.innerText += "\n\nThis machine's userAgent string is: " +
navigator.userAgent + ".";
}
//
// Retrieve the version from the user agent string and
// compare with the specified version.
//
function HasRuntimeVersion(versionToCheck)
{
var userAgentString =
navigator.userAgent.match(/.NET CLR [0-9.]+/g);
if (userAgentString != null)
{
var i;
for (i = 0; i < userAgentString.length; ++i)
{
if (CompareVersions(GetVersion(versionToCheck),
GetVersion(userAgentString[i])) <= 0)
return true;
}
}
return false;
}
//
// Extract the numeric part of the version string.
//
function GetVersion(versionString)
{
var numericString =
versionString.match(/([0-9]+)\.([0-9]+)\.([0-9]+)/i);
return numericString.slice(1);
}
//
// Compare the 2 version strings by converting them to numeric format.
//
function CompareVersions(version1, version2)
{
for (i = 0; i < version1.length; ++i)
{
var number1 = new Number(version1[i]);
var number2 = new Number(version2[i]);
if (number1 < number2)
return -1;
if (number1 > number2)
return 1;
}
return 0;
}
-->
</SCRIPT>
</HEAD>
<BODY>
<div id="result" />
</BODY>
</HTML>
在安装 .NET Framework 3.5 时,客户端计算机配置了用于 Firefox 2.0+ 的插件,该插件使 Firefox 2.0+ 可以承载 XAML 浏览器应用程序 (XBAP)。下面的示例脚本在检查“Windows Presentation Foundation”插件之前,会检查脚本是否由 Firefox 2.0+ 承载。无论结果如何,该脚本都会显示相应的状态消息。
<HTML>
<HEAD>
<TITLE>Test for the Firefox Plugin for WPF</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8" />
<SCRIPT type="text/javascript">
<!--
function OnLoad()
{
// Check if browser is Firefox
if( navigator.plugins.length == 0 ) {
document.writeln("The browser must be Firefox 2.0+.");
return;
}
// Check for WPF plugin and report
var msg = "Windows Presentation Foundation Plugin for Mozilla Firefox is ";
var wpfPlugin = navigator.plugins["Windows Presentation Foundation"];
if( wpfPlugin != null ) {
document.writeln(msg + " installed.");
}
else {
document.writeln(msg + " not installed. Please install or reinstall the .NET Framework 3.5.");
}
}
-->
</SCRIPT>
</HEAD>
<BODY onload="OnLoad()" />
</HTML>
<HEAD>
<TITLE>Test for the Firefox Plugin for WPF</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8" />
<SCRIPT type="text/javascript">
<!--
function OnLoad()
{
// Check if browser is Firefox
if( navigator.plugins.length == 0 ) {
document.writeln("The browser must be Firefox 2.0+.");
return;
}
// Check for WPF plugin and report
var msg = "Windows Presentation Foundation Plugin for Mozilla Firefox is ";
var wpfPlugin = navigator.plugins["Windows Presentation Foundation"];
if( wpfPlugin != null ) {
document.writeln(msg + " installed.");
}
else {
document.writeln(msg + " not installed. Please install or reinstall the .NET Framework 3.5.");
}
}
-->
</SCRIPT>
</HEAD>
<BODY onload="OnLoad()" />
</HTML>