var dataId, token, stopUrl /* * @Description: In User Settings Edit * @Author: your name * @Date: 2019-08-12 11:35:38 * @LastEditTime: 2019-11-30 11:40:53 * @LastEditors: Please set LastEditors */ /** * @description: 判断当前系统环境 * @param {type} * @return: */ function getOS() { var os; if ( navigator.userAgent.indexOf("Android") > -1 || navigator.userAgent.indexOf("Linux") > -1 ) { os = "Android"; } else if ( navigator.userAgent.indexOf("iPhone") > -1 || navigator.userAgent.indexOf("iPad") > -1 ) { os = "iOS"; } else if (navigator.userAgent.indexOf("Windows Phone") > -1) { os = "WP"; } else { os = "Others"; } return os; } /** * @description: 判定是否是移动端 * @Author: * @param {type} * @return: mobile_flag: 移动设备类型 */ function isMobile() { var userAgentInfo = navigator.userAgent; var mobileAgents = [ "Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod" ]; var mobile_flag = 2; for (var v = 0; v < mobileAgents.length; v++) { if (userAgentInfo.indexOf(mobileAgents[v]) > 0) { mobile_flag = 1; break; } } var screen_width = window.screen.width; var screen_height = window.screen.height; if (screen_width < 500 && screen_height < 800) { mobile_flag = 1; } return mobile_flag; } function addData() { //获取token token = localStorage.getItem("tooken"); //获取:localStorage.getItem(key) 如果key不存在 则返回null if (!token) { var registerObj = { brand: navigator.appName, //浏览器的名称 os_name: getOS(), method: "pmd.web.data.register" }; $.ajax({ type: "post", async: false, url: url+'/rest.htmp/rest', data: registerObj, dataType: "json", success: function (data) { localStorage.setItem("tooken", data.retValue.appkey); //存储数据 token = localStorage.getItem("tooken"); }, error: function (data) { } }); } stopUrl = window.location.href; //获取页面url var from_url = ""; //Document.referrer 返回 跳转或打开到当前页面 的页面的 URI。 if (document.referrer != "") { from_url = document.referrer; } var where = document.referrer; var from_id = "2"; // 来源,1搜索引擎,2直接访问,3外部链接,4内部链接 5二维码 var from_search_id = 0; //搜索引擎类型 1百度 2谷歌 3360 4搜狗 if (where.indexOf("baidu") > 0) { from_id = 1; from_search_id = 1; } else if (where.indexOf("google") > 0) { from_id = 1; from_search_id = 2; } else if (where.indexOf("360") > 0) { from_id = 1; from_search_id = 3; } else if (where.indexOf("sogou") > 0) { from_id = 1; from_search_id = 4; } var formObj = { type: isMobile(), from_id: from_id, from_search_id: from_search_id, from_url: from_url, url: stopUrl, token: token, method: "pmd.web.data.add" }; $.ajax({ type: "post", url: url+'/rest.htmp/rest', async: false, data: formObj, dataType: "json", success: function (data) { dataId = data.retValue.data_id; window.onbeforeunload = function (params) { close(dataId, stopUrl, token) } }, error: function (data) { } }); } function close(id, stopUrl, token) { $.ajax({ type: "post", url: url+'/rest.htmp/rest', async: false, data: { data_id: id, stop_url: stopUrl, token: token, method: "pmd.web.data.stopurl" }, dataType: "json", success: function (data) { }, error: function (data) { } }); } addData();