微信小程序防止截屏录屏

一、使用css添加水印

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

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

wxml文件:

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

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

css文件:

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手机截屏或者录屏时,禁止调用,并提示无法截屏。

参数

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

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

javascript 复制代码
  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('用户截屏了')
    })
  },
})

微信开发者文档wx.setVisualEffectOnCapture

相关推荐
show4331 天前
多格式导出怎么做?2026免费小程序TXT/SRT实践
开发语言·小程序·c#
AI砖家1 天前
AI编程—微信小程序开发规范
微信小程序·小程序·notepad++·ai编程
show4331 天前
2026小程序端视频转文字技术对比:识别引擎精度实测
小程序·音视频
sam-zy2 天前
微信小程序+ESP8266+Arduino 开发智能插座,有本地OTA功能
微信小程序·小程序
A24207349302 天前
微信小程序开发:常用基础语法与指令详解
微信小程序·小程序·notepad++
黄华SJ520it2 天前
青蓝送水类型社交裂变小程序系统技术拆解
小程序·系统开发
weikecms2 天前
星巴克API接口,星巴克点餐接口开发
大数据·小程序
游戏开发爱好者83 天前
系统状态:专为iPhone和iPad设计的实时系统性能监控工具全面介绍
android·ios·小程序·uni-app·iphone·webview·ipad
2501_915909063 天前
全面解析iOS应用上架到App Store的完整流程与关键注意事项
android·macos·ios·小程序·uni-app·cocoa·iphone
千舟软件3 天前
千舟软件介绍 | 顺便聊聊我们做了哪些产品
大数据·数据库·科技·小程序·业界资讯