柚子快報(bào)激活碼778899分享:微信小程序防止截屏錄屏
柚子快報(bào)激活碼778899分享:微信小程序防止截屏錄屏
一、使用css添加水印
使用微信小程序原生的view和css給屏幕添加水印這樣可以防止用戶將小程序內(nèi)的隱私數(shù)據(jù)進(jìn)行截圖或者錄屏分享導(dǎo)致信息泄露,給小程序添加一個(gè)水印浮層。這樣即使被截圖或者拍照,也能輕松地確定泄露的源頭。效果圖如下:
代碼片段?https://developers.weixin.qq.com/s/V9dcdgmc7mOy
wxml文件:
注意回車符“\n”只能被text標(biāo)簽識(shí)別view標(biāo)簽無法識(shí)別
css文件:
.water_top{
position: fixed;
top:0;
bottom: 0;
left: 0;
right: 0;
/* background: #999; */
transform:rotate(-10deg);
/* opacity: 0.9; */
z-index: -999;
}
.water-text{
float: left;
width:375rpx;
color: rgba(169,169,169,.2);
text-align: center;
font-size: 40rpx;
margin: 100rpx 0;
}
.watermark {
position: fixed;
top: 0;
width: 100%;
height: 100%;
background: #eeeeee11;
pointer-events: none;
background-repeat: repeat;
background-size: 50% auto;
}
.canvas {
width: 200px;
height: 200px;
position: fixed;
left: -200%;
}
二、使用微信小程序的api阻止用戶截屏
使用wx.setVisualEffectOnCapture手機(jī)截屏或者錄屏?xí)r,禁止調(diào)用,并提示無法截屏。
參數(shù)
屬性類型默認(rèn)值必填說明visualEffectstringnone否截屏/錄屏?xí)r的表現(xiàn),僅支持 none / hidden,傳入 hidden 則表示在截屏/錄屏?xí)r隱藏屏幕successfunction否接口調(diào)用成功的回調(diào)函數(shù)failfunction否接口調(diào)用失敗的回調(diào)函數(shù)completefunction否接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會(huì)執(zhí)行
注意:iOS 要求基礎(chǔ)庫版本為 3.3.0 以上,且系統(tǒng)版本為 iOS 16 以上
onLoad() {
wx.setVisualEffectOnCapture({
visualEffect: 'hidden',
success:(res) => {
console.log(res)
},
fail:(err) => {
console.log(err)
},
complete:(res) => {
console.log(res)
}
})
wx.onUserCaptureScreen(function (res) {
console.log('用戶截屏了')
})
},
})
微信開發(fā)者文檔wx.setVisualEffectOnCapture
柚子快報(bào)激活碼778899分享:微信小程序防止截屏錄屏
相關(guān)閱讀
本文內(nèi)容根據(jù)網(wǎng)絡(luò)資料整理,出于傳遞更多信息之目的,不代表金鑰匙跨境贊同其觀點(diǎn)和立場。
轉(zhuǎn)載請注明,如有侵權(quán),聯(lián)系刪除。