JS - 安卓 苹果 禁用 微信调整字体大小
2022-01-18 •
评论
window.addEventListener('popstate', function () {
history.pushState(null, null, document.URL)
})
// 获取与毫秒数的转化比例(相差天数:1,相差小时数:2,相差分钟数:3,相差秒数:4)
getDifferScale(value) {
var format
// 获取转化比(天数跟毫秒数的比例)
if (value === 1) {
format = parseFloat(24 * 60 * 60 * 1000)
} else if (value === 2) { // 获取转化比(小时数跟毫秒数的比例)
format = parseFloat(60 * 60 * 1000)
} else if (value === 3) { // 获取转化比(分钟数跟毫秒数的比例)
format = parseFloat(60 * 1000)
} else if (value === 4) { // 获取转化比(秒数跟毫秒数的比例)
format = parseFloat(1000)
}
return format
},
// firstDate: 2021-08-11 00:00:00
// 获取两个日期的相差日期数(differ 相差天数:1、相差小时数:2、相差分钟数:3、相差秒数:4)
getDifferDate(firstDate, secondDate, differ) {
// 1)将两个日期字符串转化为日期对象
let startDate = new Date(firstDate) let endDate = new Date(secondDate)
// 2)计算两个日期相差的毫秒数
let msecNum = endDate.getTime() - startDate.getTime()
// 3)计算两个日期相差的天数
return Math.floor(msecNum / this.getDifferScale(differ))
}
// js 取父窗口的元素
window.parent.document.getElementById("idName");
// jquery 取父窗口的元素
$('#idName', window.parent.document);
// jquery 取父窗口的父窗口的元素
$('#idName', window.parent.parent.document);
// 内容是否有修改
// true:未改变;false:改变了
isChange() {
if(this.Compare(this.dialog.detail.form, this.dialog.detail.oldForm)){
console.log('未改变');
}else{
console.log('改变');
}
return this.Compare(this.dialog.detail.form, this.dialog.detail.oldForm);
},
/**************************************比较json-start***************************************/
isObj(object) {
return object && typeof(object) == 'object' && Object.prototype.toString.call(object).toLowerCase() == "[object object]";
},
isArray(object) {
return object && typeof(object) == 'object' && object.constructor == Array;
},
getLength(object) {
var count = 0;
for(var i in object) count++;
return count;
},
CompareObj(objA, objB, flag) {
for(var key in objA) {
if(!flag) //跳出整个循环
break;
if(!objB.hasOwnProperty(key)) {
flag = false;
break;
}
if(!this.isArray(objA[key])) { //子级不是数组时,比较属性值
if(objB[key] != objA[key]) {
flag = false;
break;
}
} else {
if(!this.isArray(objB[key])) {
flag = false;
break;
}
var oA = objA[key],
oB = objB[key];
if(oA.length != oB.length) {
flag = false;
break;
}
for(var k in oA) {
if(!flag) //这里跳出循环是为了不让递归继续
break;
flag = this.CompareObj(oA[k], oB[k], flag);
}
}
}
return flag;
},
Compare(objA, objB) {
if(!this.isObj(objA) || !this.isObj(objB)) return false; //判断类型是否正确
if(this.getLength(objA) != this.getLength(objB)) return false; //判断长度是否一致
return this.CompareObj(objA, objB, true); //默认为true
},
/**************************************比较json-end***************************************/
var arr = [
{far:123.45,address:"金粮路"},
{far:3685.45,address:"北京路"},
{far:2.8,address:"人民公园"},
];
//
arr.sort(function (a, b) {
if (a.far < b.far) {
return -1;
} else if (a.far == b.far) {
return 0;
} else {
return 1;
}
function initMouseout() {
document.body.addEventListener('mouseout', (evt) => {
if (!evt) var evt = window.event;
var to = evt.relatedTarget || evt.toElement;
if (!to || to.nodeName == "HTML") {
$('#menu_hover_bg')
.stop()
.animate({
height: '0'
}, 100);
}
});
}
function getBrowserInfo(){
var ua = navigator.userAgent.toLocaleLowerCase();
var browserType=null;
if (ua.match(/msie/) != null || ua.match(/trident/) != null) {
browserType = "IE";
browserVersion = ua.match(/msie ([\d.]+)/) != null ? ua.match(/msie ([\d.]+)/)[1] : ua.match(/rv:([\d.]+)/)[1];
} else if (ua.match(/firefox/) != null) {
browserType = "火狐";
}else if (ua.match(/ubrowser/) != null) {
browserType = "UC";
}else if (ua.match(/opera/) != null) {
browserType = "欧朋";
} else if (ua.match(/bidubrowser/) != null) {
browserType = "百度";
}else if (ua.match(/metasr/) != null) {
browserType = "搜狗";
}else if (ua.match(/tencenttraveler/) != null || ua.match(/qqbrowse/) != null) {
browserType = "QQ";
}else if (ua.match(/maxthon/) != null) {
browserType = "遨游";
}else if (ua.match(/chrome/) != null) {
var is360 = _mime("type", "application/vnd.chromium.remoting-viewer");
function _mime(option, value) {
var mimeTypes = navigator.mimeTypes;
for (var mt in mimeTypes) {
if (mimeTypes[mt][option] == value) {
return true;
}
}
return false;
}
if(is360){
browserType = '360';
}else{
$('html').css("zoom",".80");
}
}else if (ua.match(/safari/) != null) {
browserType = "Safari";
}
}