var statIdName="vlstatId"; var web_url=window.location.href; var web_host=window.location.host; var web_height=window.screen.height; var web_width=window.screen.width; var web_brower=getBrower(); var web_brower_language=getBrowerLanguage(); var web_platform=getPlatform(); var web_title=getPageTitle(); var domain=web_host; var online=navigator.onLine; /*连接类型 比如WiFi 4G 3G*/ var network=''; //network=navigator.connection.type; var jsuser=0; var expiredays=30000; var times=getTimestamp(); var phonetype=getPhoneType(); var logurl='/writelog.htm?t='+times; var from_url=document.referrer; var code='Q0Q3RFVDWHJ0MDVnZXZhNFhHS3NmQ3FFaEF3RWtGZFZhUDlYUA%3D%3D'; var mob_plat=mob_plat(); /*关闭当前窗口,按下 F5 或点击以下链接触发 事件 页面关闭后写入当前页面的关闭时间 通过时间戳+url来更新 */ window.onbeforeunload = function(event){ write_log(1); }; /*页面加载后执行写入log功能*/ $(function(){ var jsuser=getCookie('userid'); //console.log(domain); //console.log(jsuser); if (jsuser=='' || jsuser=='0' || jsuser==0) { jsuser=times; setCookie('userid',jsuser,expiredays); } write_log(2); }) /*提交日志请求*/ function write_log(ty) { jsuser=getCookie('userid'); //console.log(jsuser); $.ajax({ type:"POST",url:logurl, data:"web_url="+web_url+"&web_host="+web_host+"&web_height="+web_height+"&web_width="+web_width+"&web_brower="+web_brower+"&web_brower_language="+web_brower_language+"&web_platform="+web_platform+"&web_title="+web_title+"&online="+online+"&network="+network+"&jsuser="+jsuser+"&phonetype="+phonetype+"&ty="+ty+"&from_url="+from_url+"&code="+code+"&mob_plat="+mob_plat+"&lm="+lm+"&id="+id, success:function(msg){console.log(jsuser);console.log(msg);} }); return false; } /*判断手机操作系统(ios或者是Android)*/ function mob_plat() { var u = navigator.userAgent, app = navigator.appVersion; var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //g var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端 if (isAndroid) {return 'android';}if (isIOS) {return 'ios';} return 'pc'; } /*获取手机型号函数*/ function getPhoneType() { var pattern_phone = new RegExp("iphone","i"); var pattern_android = new RegExp("android","i"); var userAgent = navigator.userAgent.toLowerCase(); var isAndroid = pattern_android.test(userAgent); var isIphone = pattern_phone.test(userAgent); var phoneType="phoneType"; if(isAndroid) { var zh_cnIndex = userAgent.indexOf("-"); var spaceIndex = userAgent.indexOf("build",zh_cnIndex+4); var fullResult = userAgent.substring(zh_cnIndex,spaceIndex); phoneType=fullResult.split(";")[1]; } else if(isIphone) { var wigth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; if(wigth>400){ phoneType="iphone6 plus";} else if(wigth>370){ phoneType="iphone6";} else if(wigth>315){ phoneType="iphone5 or iphone5s";} else{phoneType="iphone 4s";} } else { phoneType = "unkown"; } return phoneType; } /*设置cookieId*/ function setCookie(c_name,value,expiredays){ var exdate = new Date();exdate.setDate(exdate.getDate()+expiredays); document.cookie=c_name+"="+escape(value)+((expiredays==null)?"":";expires="+exdate.toGMTString())+";path=/;domain="+domain; } /*获取cookieId*/ function getCookie(c_name){ if (document.cookie.length > 0){ c_start = document.cookie.indexOf(c_name + "="); if (c_start != -1) { c_start = c_start + c_name.length + 1;c_end = document.cookie.indexOf(";", c_start); if (c_end == -1) {c_end = document.cookie.length;}return unescape(document.cookie.substring(c_start, c_end)); } } return ""; } /*获取当前时间戳*/ function getTimestamp(){var timestamp=Date.parse(new Date());return timestamp;} /*生成statId*/ function genStatId(){var cookieId = getTimestamp();cookieId="vlstat"+"-"+cookieId+"-"+Math.round(Math.random()*3000000000);return cookieId;} /*设置StatId*/ function setStatId(){var cookieId = genStatId();setCookie(statIdName, cookieId, 365);} /*获取StatId*/ function getStatId(){var statId=getCookie(statIdName);if (statId != null && statId.length>0){return statId;}else{setStatId();return getStatId();}} /*获取UA*/ function getUA(){var ua=navigator.userAgent;if (ua.length>250) {ua=ua.substring(0,250);}return ua;} /*获取浏览器类型*/ function getBrower() { var ua = getUA(); if (ua.indexOf("Maxthon") != -1) {return "Maxthon";} else if(ua.indexOf("MSIE") != -1) {return "MSIE";} else if(ua.indexOf("Firefox") != -1) {return "Firefox";} else if(ua.indexOf("Chrome") != -1) {return "Chrome";} else if(ua.indexOf("Opera") != -1) {return "Opera";} else if(ua.indexOf("Safari") != -1) {return "Safari";} else{return "ot";} } /*浏览器语言*/ function getBrowerLanguage(){var lang=navigator.browserLanguage;return lang!=null && lang.length>0 ? lang:"";} /*操作系统*/ function getPlatform(){return navigator.platform;} /*title*/ function getPageTitle(){return document.title;} /*创建form */ function createSubmitForm(){var frm=document.createElement("form");document.body.appendChild(frm);frm.method = "POST";return frm;} /*form创建元素*/ function createFormElement(frmInput, elementName, elementValue) { var element = document.createElement("input"); element.setAttribute("id", elementName); element.setAttribute("name", elementName); element.setAttribute("type", "hidden"); element.setAttribute("value", elementValue); frmInput.appendChild(element); return element; }