Skip to content

Commit

Permalink
add Detect-DotNet-For-IE.js (ie内核浏览器检测.net版本信息)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoqingqing committed Aug 19, 2016
1 parent 9075e88 commit 41405a5
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 0 deletions.
66 changes: 66 additions & 0 deletions web-w3c/Detect-DotNet-For-IE.html
@@ -0,0 +1,66 @@
<HTML>

<HEAD>
<TITLE>Test for the .NET Framework 3.5</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8" />
<script type="text/javascript">
//only for ie browser. chrome and firefox userAgent not contiant .net info so detech failed.
var dotNETRuntimeVersion = "3.5.0.0";
window.onload = function() {
if (HasRuntimeVersion(dotNETRuntimeVersion)) {
//installed dotnet
result.innerText = "This machine has the correct version of the .NET Framework 3.5."
} else {
//not install dotnet
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) {
if (versionString != null) {
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(compareVer, sourceVer) {
if (compareVer == null || sourceVer == null) {
//console.log("CompareVersions version maybe null ,compareVer:" + compareVer + " ,userVer:" + sourceVer);
return 2;
}
for (i = 0; i < compareVer.length; ++i) {
var number1 = new Number(compareVer[i]);
var number2 = new Number(sourceVer[i]);
if (number1 < number2)
return -1;
if (number1 > number2)
return 1;
}
return 0;
}
</script>
</HEAD>

<BODY>
<div id="result" />
</BODY>

</HTML>
52 changes: 52 additions & 0 deletions web-w3c/Detect-DotNet-For-IE.js
@@ -0,0 +1,52 @@
//only for ie browser. chrome and firefox userAgent not contiant .net info so detech failed.
var dotNETRuntimeVersion = "3.5.0.0";
window.onload = function() {
if (HasRuntimeVersion(dotNETRuntimeVersion)) {
//installed dotnet
result.innerText = "This machine has the correct version of the .NET Framework 3.5."
} else {
//not install dotnet
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) {
if (versionString != null) {
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(compareVer, sourceVer) {
if (compareVer == null || sourceVer == null) {
//console.log("CompareVersions version maybe null ,compareVer:" + compareVer + " ,userVer:" + sourceVer);
return 2;
}
for (i = 0; i < compareVer.length; ++i) {
var number1 = new Number(compareVer[i]);
var number2 = new Number(sourceVer[i]);
if (number1 < number2)
return -1;
if (number1 > number2)
return 1;
}
return 0;
}

0 comments on commit 41405a5

Please sign in to comment.