浏览器缩放检测
发布时间:2021-11-03, 11:23:11 分类:HTML | 编辑 off 网址 | 辅助
正文 1948字数 409,071阅读
// 浏览器缩放检测
function detectZoom (){
var ratio = 0,
screen = window.screen,
ua = navigator.userAgent.toLowerCase();
if (window.devicePixelRatio !== undefined) {
ratio = window.devicePixelRatio;
}else if (~ua.indexOf('msie')) { // ie
if (screen.deviceXDPI && screen.logicalXDPI) {
ratio = screen.deviceXDPI / screen.logicalXDPI;
}
}
else if (window.outerWidth !== undefined && window.innerWidth !== undefined) {
ratio = window.outerWidth / window.innerWidth;
}
if (ratio){
ratio = Math.round(ratio * 100);
}
return ratio;
};
Run code
Cut to clipboard
let detectZoom=this.detectZoom();
if(100!=detectZoom){
const h = this.$createElement;
this.$notify({
title: '警告',
message: h('b', { style: 'color: red;font-size:14px;'}, '您的浏览器页面可能处于缩放 ('+detectZoom+'%)状态,这可能引起页面混乱,请尝试按 Ctrl+0 重置后刷新'),
duration: 0
});
}
Run code
Cut to clipboard
detectZoom (){
let ratio = 0,
screen = window.screen,
ua = navigator.userAgent.toLowerCase();
if (window.devicePixelRatio !== undefined) {
ratio = window.devicePixelRatio;
}else if (~ua.indexOf('msie')) { // ie
if (screen.deviceXDPI && screen.logicalXDPI) {
ratio = screen.deviceXDPI / screen.logicalXDPI;
}
}
else if (window.outerWidth !== undefined && window.innerWidth !== undefined) {
ratio = window.outerWidth / window.innerWidth;
}
if (ratio){
ratio = Math.round(ratio * 100);
}
return ratio;
},
Run code
Cut to clipboard
(支付宝)给作者钱财以资鼓励 (微信)→
有过 1 条评论 »
The given payload is invalid.
问题:
使用EasyWeChat提示The given payload is invalid.
$user_info = $mp->encryptor->decryptData($session_key, $request->iv, $request->encryptedData);
EasyWechat 小程序获取手机号onGetPhoneNumber解密消息 有时会出现 The given payload is invalid. 数据无效。
解决方案:
获取用来生成 session_key 的 code 需要在获取 encryptedData 和 iv 之前就可以。
通俗一点,先让前端执行 wx.login () 拿到 code 了,再执行 getPhoneNumber 拿 encryptedData 和 iv