判断当前浏览器是否支持localstorage,UC浏览器不考虑
function supportLocalStorage() {
/*alert(navigator.userAgent);*/
if (navigator.userAgent.indexOf('UCBrowser') > -1) {
return false;
}
var uaFlag = 0;
var uaArr = new Array('Chrome', 'MQQBrowser', 'QQ', 'TBS', 'wxwork', 'MicroMessenger', 'T7', 'baiduboxapp', 'baidubrowser', 'MiuiBrowser','NetType', 'OPR');
for (var i = 0; i < uaArr.length; i++) {
if (navigator.userAgent.indexOf(uaArr[i]) > -1) {
uaFlag = 1;
}
}
if (uaFlag != 1) {
if (navigator.userAgent.indexOf('HUAWEIEVA') > -1 || navigator.userAgent.indexOf('HUAWEIVTR') > -1) {
return false;
}
}
var testKey = 'test';
try {
window.localStorage.setItem(testKey, 'testValue');
window.localStorage.removeItem(testKey);
return true;
} catch (e) {
return false;
}
}
/*全局变量g_localStore标志了当前浏览器是否支持localstorage*/
var g_localStore = false;
try {
g_localStore = supportLocalStorage();
} catch (ex) {
}
计算缓存时长
var BehLong = {
isCache:0,//isCache标志字段是否来自缓存
sfz1:0,
phoneNum1:0,
companyName:0,
comDetail:0,
comTel:0,
firstSumLong:0,
secondSumLong:0
};
var storageQuery = ["name1","py1","sfz1","phoneNum1","id_card_certify","active_time_start","active_time_end","mail1","js_content_xzcs","detail","hPostCode","hDisNum","hPhone","married","education","companyName","comAddr1","comDetail","cDisNum","telNum","extNum","workLife","cPostCode","relativeName","relPhoneNum","relation","oPerson","oPhoneNum","oRelation"];
/*BehLong['isCache'] = 0;*/
var comTel = 0;
/*var firstSumLong;
var secondSumLong;*/
$(document).ready(function () {
if(g_localStore) {
var obj_storage = localStorage;
if(obj_storage.length > 1){
for(var key in obj_storage){
/*localstorage中有缓存字段,且字段不为空*/
if(storageQuery.indexOf(key) >= 0 && obj_storage.getItem(key) !=""){
BehLong['isCache'] = 1;
break;
}
}
}
/*console.log(BehLong);*/
}
$("#name1,#py1,#sfz1,#phoneNum1,#vercode,#companyName,#comDetail").each(function () {
var obj = $(this);
var thisId = obj.attr("id");
obj.one("focus",function () {
if($("#step1Start").val() == ""){
var step1Start = (new Date()).getTime();
$("#step1Start").val(step1Start);
}
if("sfz1,phoneNum1,companyName,comDetail".indexOf(thisId)>=0){
var start= (new Date()).getTime();
$(this).attr("focusTime",start);
}
});
});
$("#sfz1,#phoneNum1,#companyName,#comDetail").each(function () {
var obj = $(this);
var thisId = obj.attr("id");
obj.one("blur",function () {
var end= (new Date()).getTime();
var start= obj.attr("focusTime");
var diff = end - start;
BehLong[thisId] = diff/1000;
/*console.log(BehLong);*/
obj.removeAttr("focusTime");
})
});
$("#cDisNum,#telNum,#extNum").each(function () {
var obj = $(this);
obj.one("focus",function () {
var start= (new Date()).getTime();
$(this).attr("focusTime",start);
}).one("blur",function () {
var end= (new Date()).getTime();
var obj =$(this);
var start= obj.attr("focusTime");
var diff = end - start;
comTel = comTel + diff;
BehLong["comTel"] = comTel/1000;
/*console.log(BehLong);*/
$(this).removeAttr("focusTime");
})
});
});