3二次开拓入门,浏览器检验JS代码
分类:pc28.am

废话不多说了,下面通过一段代码示例介绍一下,希望能够给需要的朋友带来或多或少的帮助。

关于机器用的操作系统,我们可以随便点击下鼠标就能够获取,但是如何使用javascript获取本机的操作系统类型呢,下面就通过一段代码示例简单介绍一下,希望能够给需要的朋友带来或多或少的帮助。

6.1  ITerraExplorer51

主要用来获取安装在客户端的Skyline软件的版本信息及设置的工程参数等信息;提供实现数据加载、保存和事件接口的初始化等方法;

下面是对ITerraExplorer51的属性和方法的概要说明:

Type

判断客户端使用的是Pro还是Viewer;

FlyName

返回当前工程中加载的FLY文件名,没有FLY文件则返回NO_FLY ;

DisplayErrorMessages

设置为false时,COM方法调用期间如果发生错误则不显示错误信息。反之,显示错误信息;

ProjectParam

FLY工程参数环境设置;

OptionParam

TerraExplorer参数环境设置;

Load

加载FLY文件;

SetCPUSavingMode

设置CPU保存模式;

GetUserUnits

获取客户端坐标系统的使用单位;

LoadEx

加载FLY文件,需要输入用户名和密码;

GetTEVersion

获取支持的软件版本;

Save

保存当前的工程到FLY文件中;

SaveAs

保存当前的工程到指定的FLY文件中,不支持TerraExplorer Viewer ;

SetParam

保留,当前不能使用;

GetParam

保留,当前不能使用;

AttachEvent

保留,当前不能使用;

DetachEvent

保留,当前不能使用;

 

代码示例:(操作系统:Windows XP SP3;代码调试环境VS2010,DotNet4.0,IE7,IIS6.0)

【C#】

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using TerraExplorerX;



namespace ExCodeProject

{

    public partial class Form1 : Form

    {

        private TerraExplorer TE;

        private ITerraExplorer51 TE51;



        public Form1()

        {

            InitializeComponent();



            this.TE = new TerraExplorerClass();

            this.TE51 = (ITerraExplorer51)TE;



            TE51.Load(Application.StartupPath "\Default.fly");



        }

    }

}

  

【javascript】

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>Skyline二次开发教程【配套示例】</title>   

    <script type ="text/javascript">

        function Init() {

            var TE = _$SGCreateTEObj();

            var ITerraExplorer = TE.interface("ITerraExplorer51");

            ITerraExplorer.Load("D:\2010售前演示系统\WPFA-DEMO\WPFA-DEMO\bin\Debug\FLY\Default.fly");

        }

        //------------------------------------------------------------

        // 创建三维对象 赵贺 2009.01.25.

        //------------------------------------------------------------

        function _$SGCreateTEObj() {

            var obj = window.document.getElementById("TE");

            if (obj == null) {

                obj = document.createElement('object');

                document.body.appendChild(obj);

                obj.name = "TE";

                obj.id = "TE";

                obj.classid = "CLSID:3a4f9191-65a8-11d5-85c1-0001023952c1";

            }

            return obj;

        }

    </script>

</head>

<body onload = "Init()">

    <form id="form1" runat="server">

    <div id = "Title"></div>

    <div id="Main">

        <object id="TerraExplorer3DWindow" classid="CLSID:3a4f9192-65a8-11d5-85c1-0001023952c1"

            width="521" height="521">

        </object>

    </div>

    </form>

</body>

</html>

  

 

 

 

浏览器检测JS代码(兼容目前各大主流浏览器),js主流

本文实例介绍了JS代码实现浏览器检测,分享给大家供大家参考,具体内容如下

var BrowserMatch = {
  init: function () {
    this.browser = this.getBrowser().browser || "An Unknown Browser";
    this.version = this.getBrowser().version || "An Unknown Version";
    this.OS = this.getOS() || "An Unknown OS";
  },
  getOS:function(){
    if(navigator.platform.indexOf("Win")!= -1) return "Windows";
    if(navigator.platform.indexOf("Mac")!= -1) return "Mac";
    if(navigator.platform.indexOf("Linux")!= -1) return "Linux";
    if(navigator.userAgent.indexOf("iPhone")!= -1) return "iPhone/iPod";
  },
  getBrowser:function () {
    var rMsie = /(msies|trident/7)([w.] )/;
    var rTrident = /(trident)/([w.] )/;
    var rFirefox = /(firefox)/([w.] )/; 
    var rOpera = /(opera). version/([w.] )/;
    var rNewOpera = /(opr)/(. )/;
    var rChrome = /(chrome)/([w.] )/;
    var rSafari = /version/([w.] ).*(safari)/;
    var ua = navigator.userAgent.toLowerCase();
    var matchBS,matchBS2;
    matchBS = rMsie.exec(ua);
    if (matchBS != null) {
      matchBS2 = rTrident.exec(ua);
      if (matchBS2 != null){
        switch (matchBS2[2]){
          case "4.0": return { browser : "IE", version : "8" };break;
          case "5.0": return { browser : "IE", version : "9" };break;
          case "6.0": return { browser : "IE", version : "10" };break;
          case "7.0": return { browser : "IE", version : "11" };break;
          default:return { browser : "IE", version : "Undefined" };
        }
      }else{
        return {browser : "IE", version : matchBS[2] || "0" };
      }
    }
    matchBS = rFirefox.exec(ua);  
    if ((matchBS != null)&&(!(window.attachEvent))&&(!(window.chrome))&&(!(window.opera))) {  
      return { browser : matchBS[1] || "", version : matchBS[2] || "0" };
    }
    matchBS = rOpera.exec(ua);         
    if ((matchBS != null)&&(!(window.attachEvent))) {     
      return { browser : matchBS[1] || "", version : matchBS[2] || "0" };
    }
    matchBS = rChrome.exec(ua);  
    if ((matchBS != null)&&(!!(window.chrome))&&(!(window.attachEvent))) {
      matchBS2 = rNewOpera.exec(ua);       
      if(matchBS2 == null){
        return { browser : matchBS[1] || "", version : matchBS[2] || "0" };
      }else{
        return { browser : "Opera", version : matchBS2[2] || "0" };
      }  
    }
    matchBS = rSafari.exec(ua);          
    if ((matchBS != null)&&(!(window.attachEvent))&&(!(window.chrome))&&(!(window.opera))) {   
      return { browser : matchBS[2] || "", version : matchBS[1] || "0" };
    }           
  }
};  
BrowserMatch.init();

调用方法:(首先得引入js文件,大家应该都懂的)

获取浏览器名:**BrowserMatch.browser;**

获取浏览器版本:**BrowserMatch.version;**

获取所处操作系统:**BrowserMatch.OS;**

以上就是本文的全部内容,希望对大家的学习有所帮助。

示例代码:

function GetOSInfo(){ var _pf=navigator.platform; var appVer=navigator.userAgent; if(_pf=="Win32" || _pf == "Windows") { if(appVer.indexOf { _bit = "64位"; } else { _bit = "32位"; } if(appVer.indexOf > -1 || appVer.indexOf > -1) { if(_bit=='64位' || appVer.indexOf > -1) { return 'Windows_vista ' _bit; } else { return "Unknow1"; } } else if(appVer.indexOf > -1 || appVer.indexOf { if(_bit=='32位' || appVer.indexOf { return 'Windows_7 ' _bit; } else { return "Unknow"; } } else { try { var _winName = Array; var _ntNum = appVer.match.toString(); return 'Windows_'   _winName[_ntNum.replace/i,"$1")] " " _bit; } catch { return 'Windows'; } } } else if(_pf == "Mac68K" || _pf == "MacPPC" || _pf == "Macintosh") { return "Mac"; } else if { return "Unix"; } else if.indexOf { return "Linux"; } else { return "Unknow"; } }

//&#33719;&#21462;&#23458;&#25143;&#31471;&#25805;&#20316;&#31995;&#32479;&#31867;&#22411; function detectOS() { var sUserAgent = navigator.userAgent; var isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows"); var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh") || (navigator.platform == "MacIntel"); if  return "Mac"; var isUnix = (navigator.platform == "X11") &amp;&amp; !isWin &amp;&amp; !isMac; if  return "Unix"; var isLinux = (String.indexOf; if  return "Linux"; if  { var isWin2K = sUserAgent.indexOf &gt; -1 || sUserAgent.indexOf &gt; -1; if  return "Win2000"; var isWinXP = sUserAgent.indexOf &gt; -1 || sUserAgent.indexOf &gt; -1; if  return "WinXP"; var isWin2003 = sUserAgent.indexOf &gt; -1 || sUserAgent.indexOf &gt; -1; if  return "Win2003"; var isWin2003 = sUserAgent.indexOf &gt; -1 || sUserAgent.indexOf &gt; -1; if  return "WinVista"; var isWin2003 = sUserAgent.indexOf &gt; -1 || sUserAgent.indexOf &gt; -1; if  return "Win7"; } return "None"; } function locationHref{ case 'Mac': window.location.href='http://www.baidu.com'; break; case 'Unix': window.location.href='http://tieba.baidu.com'; break; case 'Linux': window.location.href='http://map.baidu.com'; break; case 'Win2000': window.location.href='http://mp3.baidu.com'; break; case 'WinXP': window.location.href='http://baike.baidu.com'; break; case 'Win2003': window.location.href='http://zhidao.baidu.com'; break; case 'WinVista': window.location.href='http://hi.baidu.com'; break; case 'Win7': window.location.href='http://video.baidu.com'; break; default : window.location.href='http://www.hao123.com/'; break; } }var kk=detectOS;/*locationHref;*/

您可能感兴趣的文章:

  • JavaScript 检测浏览器和操作系统的脚本
  • 用js实现的检测浏览器和系统的函数
  • javascript 检测浏览器类型和版本的代码
  • javascript 特性检测并非浏览器检测
  • 使用JavaScript检测Firefox浏览器是否启用了Firebug的代码
  • JavaScript高级程序设计阅读笔记(十六) javascript检测浏览器和操作系统-detect.js
  • JavaScript快速检测浏览器对CSS3特性的支持情况
  • 使用js检测浏览器是否支持html5中的video标签的方法
  • js检测浏览器版本、核心、是否移动端示例
  • javascript检测浏览器的缩放状态实现代码

本文实例介绍了JS代码实现浏览器检测,分享给大家供大家参考,具体内容如下 var B...

function GetOSInfo(){ var _pf=navigator.platform; var appVer=navigator.userAgent; if(_pf=="Win32" || _pf == "Windows") { if(appVer.indexOf { _bit = "64位"; } else { _bit = "32位"; } if(appVer.indexOf > -1 || appVer.indexOf > -1) { if(_bit=='64位' || appVer.indexOf > -1) { return 'Windows_vista ' _bit; } else { return "Unknow1"; } } else if(appVer.indexOf > -1 || appVer.indexOf { if(_bit=='32位' || appVer.indexOf { return 'Windows_7 ' _bit; } else { return "Unknow"; } } else { try { var _winName = Array; var _ntNum = appVer.match.toString(); return 'Windows_'   _winName[_ntNum.replace/i,"$1")] " " _bit; } catch { return 'Windows'; } } } else if(_pf == "Mac68K" || _pf == "MacPPC" || _pf == "Macintosh") { return "Mac"; } else if { return "Unix"; } else if.indexOf { return "Linux"; } else { return "Unknow"; } }

以上就是js获取本机操作系统类型的方法,希望大家有所收获。

以上代码很简单的实现了javascript获取本机操作系统类型的方法,一下在通过一段示例代码介绍javascript获取操作系统版本信息

javascript获取操作系统版本信息

示例代码:

var sUserAgent = navigator.userAgent;var fAppVersion = parseFloat;//比较浏览器版本大小function compareVersions{ var aVersion1 = sVersion1.split; var aVersion2 = sVersion2.split; if(aVersion1.length>aVersion2.length){ for(var i=0;iaVersion2[i]) return 1; } return 0;}//检测是否Opera浏览器var isOpera = sUserAgent.indexOf>-1;var isMinOpera4 = isMinOpera5 = isMinOpera6 = isMinOpera7 = isMinOpera7_5 = false;if{ var fOperaVersion; if(navigator.appName == "Opera"){ fOperaVersion = fAppVersion; } else { var reOperaVersion = new RegExp("Opera (http://www.cnblogs.com/eoiioe/admin/file://d ///d )"); reOperaVersion.test; fOperaVersion = parseFloat; } isMinOpera4 = fOperaVersion >= 4; isMinOpera5 = fOperaVersion >= 5; isMinOpera6 = fOperaVersion >= 6; isMinOpera7 = fOperaVersion >= 7; isMinOpera7_5 = fOperaVersion >= 7.5;}//检测是否Safarivar isKHTML = sUserAgent.indexOf>-1 || sUserAgent.indexOf>-1 || sUserAgent.indexOf>-1;var isMinSafari1 = isMinSafari1_2 = false;var isMinKonq2_2 = isMinKonq3 = isMinKonq3_1 = isMinKonq3_2 = false;if{ isSafari = sUserAgent.indexOf>-1; isKonq = sUserAgent.indexOf>-1; if{ var reAppleWebKit = new RegExp("AppleWebKit\/(http://www.cnblogs.com/eoiioe/admin/file://d "); reAppleWebKit.test; var fAppleWebKitVersion = parseFloat; isMinSafari1 = fAppleWebKitVersion >= 85; isMinSafari1_2 = fAppleWebKitVersion >= 124; } else if  { var reKonq = new RegExp("Konqueror\/(http://www.cnblogs.com/eoiioe/admin/file://d (/?:\.\d ?)"); reKonq.test; isMinKonq2_2 = compareVersions >= 0; isMinKonq3 = compareVersions >= 0; isMinKonq3_1 = compareVersions >= 0; isMinKonq3_2 = compareVersions >= 0; }}//检测IEvar isIE = sUserAgent.indexOf > -1 &&sUserAgent.indexOf > -1 &&!isOpera;var isMinIE4 = isMinIE5 = isMinIE5_5 = isMinIE6 = isMinIE7 = false;if{ var reIE = new RegExp("MSIE (http://www.cnblogs.com/eoiioe/admin/file://d ///d );"); reIE.test; var fIEVersion = parseFloat; isMinIE4 = fIEVersion >=4; isMinIE5 = fIEVersion >=5; isMinIE5_5 = fIEVersion >=5.5; isMinIE6 = fIEVersion >=6; isMinIE7 = fIEVersion >=7;}//检测Firfoxvar isFF = sUserAgent.indexOf>-1&&!isKHTML;var isMinFF1 = isMinFF2 =isMinFF3 = false;if{ var reFF = new RegExp("Firefox\/(http://www.cnblogs.com/eoiioe/admin/file://d ///d ?)"); reFF.test; isMinFF1 = compareVersions >=0; isMinFF2 = compareVersions >=0; isMinFF3 = compareVersions >=0;}//检测Mozillavar isMoz = sUserAgent.indexOf>-1&&!isKHTML;var isMinMoz1 = isMinMoz1_4 = isMinMoz1_5 = isMinMoz1_8 = false;if{ var reMoz = new RegExp("rv:(http://www.cnblogs.com/eoiioe/admin/file://d ///d "); reMoz.test; isMinMoz1 = compareVersions >=0; isMinMoz1_4 = compareVersions >=0; isMinMoz1_5 = compareVersions >=0; isMinMoz1_8 = compareVersions >=0;}var isNS4 = !isIE&&!isOpera&&!isMoz&&!isKHTML &&(sUserAgent.indexOf &&(navigator.appName == "Netscape") &&(fAppVersion >= 4.0 && fAppVersion <5.0);var isMinNS4 = isMinNS4_5 = isMinNS4_7 =isMinNS4_8 = false;if{ isMinNS4 = true; ifMinNS4_5 = fAppVersion >= 4.5; ifMinNS4_7 = fAppVersion >= 4.7; ifMinNS4_8 = fAppVersion >= 4.8;}//检测操作系统var isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows");var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh");var isUnix = (navigator.platform == "X11" && !isWin && !isMac);var isWin95 = isWin98 = isWinNT4 = isWin2K = isWinME = isWinXP = isWin2K3 = isVista = false;var isMac68K = isMacPPC = false;var isSunOS = isMinSunOS4 = isMinSunOS5 = isMinSunOS5_5 = false;//Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506)if{ isWin95 = sUserAgent.indexOf > -1 || sUserAgent.indexOf >-1; isWin98 = sUserAgent.indexOf > -1 || sUserAgent.indexOf >-1; isWinME = sUserAgent.indexOf > -1 || sUserAgent.indexOf >-1; isWin2K = sUserAgent.indexOf > -1 || sUserAgent.indexOf >-1; isWinXP = sUserAgent.indexOf > -1 || sUserAgent.indexOf >-1; isWin2K3 = sUserAgent.indexOf > -1 || sUserAgent.indexOf >-1; //检测Vista系统可能有bug isVista = sUserAgent.indexOf > -1 || sUserAgent.indexOf >-1; if{ isWinNT4 = sUserAgent.indexOf > -1 || sUserAgent.indexOf >-1 || sUserAgent.indexOf >-1 || (sUserAgent.indexOf >-1) && (!isWinME&&!isWin2K&&!isWinXP); }}if{ isMac68K = sUserAgent.indexOf > -1 || sUserAgent.indexOf > -1; isMacPPC = suserAgent.indexOf > -1 || sUserAgent.indexOf > -1;}if{ isSunOS = sUserAgent.indexOf > -1; if{ var reSunOS = new RegExp("SunOS (http://www.cnblogs.com/eoiioe/admin/file://d ///d "); reSunOS.test; isMinSunOS4 = compareVersions >= 0; isMinSunOS5 = compareVersions >= 0; isMinSunOS5_5 = compareVersions >= 0; }}document.write;document.write;document.write;document.write;document.write;document.write("Windows 操作系统:"   isWin);document.write;document.write;document.write("Mozilla 1.5 ↑:"   isMinMoz1_5);document.write;document.write("Mozilla 1.8 ↑:"   isMinMoz1_8);document.write;document.write("Firfox 1.0 ↑:"   isMinFF1);document.write;document.write("Firfox 2.0 ↑:"   isMinFF2);document.write;document.write("Firfox 3.0 ↑:"   isMinFF3);document.write;document.write("IE 4.0 ↑:"   isMinIE4);document.write;document.write("IE 5.0 ↑:"   isMinIE5);document.write;document.write("IE 5.5 ↑:"   isMinIE5_5);document.write;document.write("IE 6.0 ↑:"   isMinIE6);document.write;document.write("IE 7.0 ↑:"   isMinIE7);document.write;document.write("Windows 95:"   isWin95);document.write;document.write("Windows 98:"   isWin98);document.write;document.write("Windows ME:"   isWinME);document.write;document.write("Windows NT:"   isWinNT4);document.write;document.write("Windows 2000:"   isWin2K);document.write;document.write("Windows XP:"   isWinXP);document.write;document.write("Windows 2003:"   isWin2K3);document.write;document.write("Windows Vista:"   isVista);document.write;

无论是获取本机还是非本机的操作系统版本信息,代码都很简单,希望对大家获多或少的有点帮助。

本文由pc28.am发布于pc28.am,转载请注明出处:3二次开拓入门,浏览器检验JS代码

上一篇:JavaScript学习总括 下一篇:没有了
猜你喜欢
热门排行
精彩图文