Some Javascript functions of ClickOnce's publish.htm

  • 54181
  • 0
  • AJAX
  • 2008-03-23

Some Javascript functions of ClickOnce's publish.htm

  • 隱藏必須條件區塊
  • 偵測使用者 .NET Framework CLR 版本
  • 比較 CLR 版本

 

  1. <script type="text/javascript">
  2. function Initialize( )
  3. {
  4. var runtimeVersion = "3.5.0";
  5. var directLink = "InformationBoard5.application";
  6. var setupLink = "setup.exe";
  7. BootstrapperSection.style.display = "none";
  8. // 3.5 Version
  9. if (HasRuntimeVersion(runtimeVersion) )
  10. {
  11. InstallButton.href = directLink;
  12. }
  13. // NOT 3.5 Version
  14. else
  15. {
  16. InstallButton.href = setupLink;
  17. }
  18. }
  19. function HasRuntimeVersion(v)
  20. {
  21. var va = GetVersion(v);
  22. var i;
  23. var a = navigator.userAgent.match ( /\.NET CLR [ 0 -9.]+/g );
  24. if (a != null )
  25. for (i = 0; i < a.length; ++i)
  26. if (CompareVersions(va, GetVersion(a[i] ) ) <= 0 )
  27. return true;
  28. return false;
  29. }
  30. function GetVersion(v)
  31. {
  32. var a = v.match ( /( [ 0 -9 ]+)\. ( [ 0 -9 ]+)\. ( [ 0 -9 ]+)/i );
  33. return a.slice ( 1 );
  34. }
  35. function CompareVersions(v1, v2)
  36. {
  37. for (i = 0; i < v1.length; ++i)
  38. {
  39. var n1 = new Number(v1[i] );
  40. var n2 = new Number(v2[i] );
  41. if (n1 < n2) return -1;
  42. if (n1 > n2) return 1;
  43. }
  44. return 0;
  45. }
  46. </script>