123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- Namespace.register("U.UF.CI");
- //#region 客户端信息
- //浏览器信息
- U.UF.CI.userAgent = navigator.userAgent.toLowerCase();
- /*
- * 获取去新浪获取地址信息
- *
- * @param {function} 获取客户端信息回调
- */
- //朱艳萍老师建议:用释义的方式更加利于学生理解,也更加便于此系统的普及及应用,建议采纳。
- //Usestudio.UnionForm.getUserLocation
- U.UF.CI.getUserLocation = function (fun) {
- //如果用户客户端信息已经加载成功
- if (US.city["country"]) {
- fun(); //回调函数
- }
- else {
- //如果没有加载成功,那么通过加载新浪的api去加载
- //新浪的用不了了,现在使用的是搜狐的api
- U.UF.DL.asynLoadJs({ "src": "http://pv.sohu.com/cityjson?ie=utf-8" },
- function () {
- var _city = U.UF.CI.asyngetUserLocation(); //得到城市地址
- fun(_city); //打印城市信息
- });
- }
- }
- /*
- * 获取客户端ip异步
- returnCitySN
- 参数描述
- -------cname 当前城市
- -------cid 当前城市id
- -------cip 当前城市ip
- *
- *
- */
- U.UF.CI.asyngetUserLocation = function () {
- try {
- var _script = U.UF.DL.asynLoadJs({ "src": "http://pv.sohu.com/cityjson?ie=utf-8" }, function () { });
- //引入搜狐的script模块
- var i,
- _locationinfo = returnCitySN, //搜狐返回的值
- //用户地址信息数组
- _locationarr = [
- "country",
- "province",
- "city",
- "district",
- "isp",
- "type"
- ];
- _locationinfo.userAllLocation = ""; //用户地址拼接的处理
- //循环需要拼接的数组处理
- for (i = 0; i < _locationarr.length; i++) {
- _locationarr["userAllLocation"] += _locationarr[_locationinfo[i]];
- if (i != _locationarr.length - 1) {
- _locationarr["userAllLocation"] += ",";
- }
- }
- //把从第三方获取的值放在US.city变量中
- //alert("当前城市的ip值为" + _locationinfo.cip);
- US.city = _locationinfo;
- cb(_locationinfo); //回调使用
- }
- catch (e) { return; }
- }
- /*
- * 获取浏览器类型
- *
- * @return {object} 浏览器类型{ "browser": "", "ver": "" }
- ---------browser 浏览器类型 如 ie chrome firefox safir
- ---------ver 浏览器版本 如果ie的 7.0 8.0 和chrome 33 34
- */
- U.UF.CI.getBrowser = function () {
- var _browserobj = { "browser": "", "ver": "" }, //返回的浏览器对象
- _bri = U.UF.CI.userAgent, //浏览器信息
- _bro = U.UF.S.browser, //区分浏览器的正则
- _browserarr = _bri.match(_bro)//利用正则反选择的方式获取数组
- ;
- _browserobj.browser = _browserarr[1]; //设置浏览器的名字如 msie chrome firefox safir
- _browserobj.ver = _browserarr[2]; //设置浏览器版本号 ie的 7.0 8.0 和chrome 33 34
- return _browserobj;
- }
- /*
- * 获取用户电脑系统
- *
- * @return {string} 成功回调
- */
- U.UF.CI.getSystem = function () {
- //非window系列的说明
- var _ant = {
- "Apple series": "Mac68K,MacPPC,Macintosh",
- "Unix series": "X11",
- "Mac OS X 10_7": "OSX 10.7",
- "Mac OS X 10.8": "OSX 10.8",
- "Mac OS X 10_8": "OSX 10.8",
- "Linux": "Linux"
- };
- var _win = {
- "Windows NT 5.1": "WinXP", //windows 系列 系统信息
- "Windows NT 6.1": "Win7",
- "Windows NT 6.0": "Windows Server 2008",
- "Windows NT 6.2": "Win8",
- "Windows NT 5.1": "winxp",
- "Windows NT 5.2": "Windows Server 2003",
- "Windows NT 5.0": "Win2000",
- "Win 9x 4.90": "WinME",
- "Windows NT 10.0": "Win10"
- };
- var _str = navigator.userAgent; //获取用户信息
- var _left = _str.indexOf('(');
- var _right = _str.indexOf(';');
- //截取系统信息
- var _result = _str.substring(_left + 1, _right);
- return _win[_result] || _ant[_result]; //返回系统名称
- }
- /*
- * 判断用户支持html5 还是flash
- *
- * @return {string} 判断是否支持flash或者html5
- -----------HTML5 支持html5
- -----------Flash 支持flash
- */
- U.UF.CI.isSupportFlash = function () {
- if (typeof (Worker) !== "undefined") //利用worker属性判断是否支持html5
- {
- return 'HTML5';
- }
- else if (navigator.plugins["Shockwave Flash"]) {//利用navigator.plugins["Shockwave Flash"]属性判断是否支持flash
- return "Flash";
- }
- else {
- return false;
- }
- }
- /*
- * 获取客户端为电脑端还是手机端
- * @return {boolean}
- -----------true 电脑端
- -----------false 手机端
- */
- U.UF.CI.getUserPort = function () {
- var _userAgentInfo = navigator.userAgent, //浏览器信息
- _agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"], //常用的手机系统版本
- _flag = true, //建立标志
- i; //用于循环
- //循环判断浏览器信息中是否有手机端是否有
- for (i = 0; i < _agents.length; i++) {
- if (_userAgentInfo.indexOf(_agents[i]) > 0) {
- _flag = false; //如果是手机版本返回false
- break;
- }
- }
- return _flag; //如果不是手机端返回true
- }
- /*
- * 获取分辨率
- * @return {array} [deviceXDPI, deviceYDPI];
- */
- U.UF.CI.getDPI = function () {
- var arrDPI = new Array();
- if (window.screen.deviceXDPI != undefined) {
- arrDPI[0] = window.screen.deviceXDPI;
- arrDPI[1] = window.screen.deviceYDPI;
- }
- else {
- var tmpNode = document.createElement("DIV");
- tmpNode.style.cssText = "width:1in;height:1in;position:absolute;left:0px;top:0px;z-index:99;visibility:hidden";
- document.body.appendChild(tmpNode);
- arrDPI[0] = parseInt(tmpNode.offsetWidth);
- arrDPI[1] = parseInt(tmpNode.offsetHeight);
- tmpNode.parentNode.removeChild(tmpNode);
- }
- return arrDPI;
- }
- //#endregion
|