最近项目中遇到客户端使用.net4.0开发环境,但在打包程序时集成开发环境将安装包变得很大,想减少安装包大小。鉴于客户终端上很多都已经安装了.net环境,通过检查客户端环境选择下载无.net集成环境的安装包。
检查.net集成环境的方式在网上搜索了一下,再通过测试小小的修改了一点,记录下来方便下次用到。
<script type="text/javascript">
//var dotNETRuntimeVersion = "4.0.30319";
var dotNETRuntimeVersion = "4.0.00000";
$(document).ready(function() {
//
if (HasRuntimeVersion(dotNETRuntimeVersion)) {
$("#clientalldown").hide();
} else {
$("#clientdown").hide();
}
});
function getNetFrameVersion() {
var version = "";
var userAgentString = navigator.userAgent.match(/.NET CLR [0-9.]+/g);
if (userAgentString != null) {
var i;
for (i = 0; i < userAgentString.length; ++i) {
version += "【" + GetVersion(userAgentString[i]) + "】;";
}
}
if ((navigator.userAgent.indexOf(".NET4.0E") != -1)
&& (navigator.userAgent.indexOf(".NET4.0C")!=-1)) {
version+="【4.0+】";
}
return 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;
}
}
//在部分版本系统和浏览器中,.net4存在【.NET4.0C;.NET4.0E】两种特殊的情况
if ((CompareVersions(GetVersion(versionToCheck),GetVersion("4.0.00000"))>= 0)
&&(navigator.userAgent.indexOf(".NET4.0E") != -1)
&& (navigator.userAgent.indexOf(".NET4.0C")!=-1)) {
return true;
}
return false;
}
function GetVersion(versionString) {
var numericString = versionString
.match(/([0-9]+)\.([0-9]+)\.([0-9]+)/i);
return numericString.slice(1);
}
function CompareVersions(version1, version2) {
var i;
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>