微信小程序防止截屏录屏

一、使用css添加水印

使用微信小程序原生的view和css给屏幕添加水印这样可以防止用户将小程序内的隐私数据进行截图或者录屏分享导致信息泄露,给小程序添加一个水印浮层。这样即使被截图或者拍照,也能轻松地确定泄露的源头。效果图如下:

代码片段 https://developers.weixin.qq.com/s/V9dcdgmc7mOy

wxml文件:

注意回车符“\n”只能被text标签识别view标签无法识别


  
  1. <navigation-bar title="Weixin" back="{{false}}" color="black" background="#ccc"> </navigation-bar>
  2. <view class="water_top" style="pointer-events: none;">
  3. <text class="water-text" wx:for="{{50}}">{{"小程序水印\n12345678910"}} </text>
  4. </view>

css文件:


  
  1. .water_top{
  2. position: fixed;
  3. top: 0;
  4. bottom: 0;
  5. left: 0;
  6. right: 0;
  7. /* background: #999; */
  8. transform: rotate(- 10deg);
  9. /* opacity: 0.9; */
  10. z-index: - 999;
  11. }
  12. .water-text{
  13. float: left;
  14. width: 375rpx;
  15. color: rgba( 169, 169, 169,. 2);
  16. text-align: center;
  17. font-size: 40rpx;
  18. margin: 100rpx 0;
  19. }
  20. .watermark {
  21. position: fixed;
  22. top: 0;
  23. width: 100%;
  24. height: 100%;
  25. background: #eeeeee11;
  26. pointer-events: none;
  27. background-repeat: repeat;
  28. background-size: 50% auto;
  29. }
  30. .canvas {
  31. width: 200px;
  32. height: 200px;
  33. position: fixed;
  34. left: - 200%;
  35. }

二、使用微信小程序的api阻止用户截屏

使用wx.setVisualEffectOnCapture手机截屏或者录屏时,禁止调用,并提示无法截屏。

参数

属性类型默认值必填说明
visualEffectstringnone截屏/录屏时的表现,仅支持 none / hidden,传入 hidden 则表示在截屏/录屏时隐藏屏幕
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数
completefunction接口调用结束的回调函数(调用成功、失败都会执行

注意:iOS 要求基础库版本为 3.3.0 以上,且系统版本为 iOS 16 以上


  
  1. onLoad( ) {
  2. wx. setVisualEffectOnCapture({
  3. visualEffect: 'hidden',
  4. success: (res) => {
  5. console. log(res)
  6. },
  7. fail: (err) => {
  8. console. log(err)
  9. },
  10. complete: (res) => {
  11. console. log(res)
  12. }
  13. })
  14. wx. onUserCaptureScreen( function ( res) {
  15. console. log( '用户截屏了')
  16. })
  17. },
  18. })

微信开发者文档wx.setVisualEffectOnCapture

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值