Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat gadgets host web-view web-view


May 18, 2021 WeChat Mini Program Development Document


Table of contents


web-view

Base library 1.6.4 starts to support, and low versions need to be compatible

The web-view component is a container that can be used to host Web pages and automatically fills the entire web page. Small programs of personal type and overseas type are not supported for the time being.

The property name Type The default Description
Src String none Webview's link to a Web page. You need to log in to the small program management background configuration domain name whitelist.

Example code:

<!-- wxml -->
<!-- 指向微信公众平台首页的web-view -->
<web-view src="https://mp.weixin.qq.com/" rel="external nofollow" ></web-view>

Related interface 1

The interface provided by JSSDK 1.3.0 can be used to return to the program page. The supported interfaces are:

The name of the interface Description The lowest version
wx.miniProgram.navigateTo The parameters are consistent with the small program interface 1.6.4
wx.miniProgram.navigateBack The parameters are consistent with the small program interface 1.6.4
wx.miniProgram.switchTab The parameters are consistent with the small program interface 1.6.5
wx.miniProgram.reLaunch The parameters are consistent with the small program interface 1.6.5
wx.miniProgram.redirectTo The parameters are consistent with the small program interface 1.6.5

Example code:

<!-- html -->
<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.0.js" rel="external nofollow" ></script>

// javascript
wx.miniProgram.navigateTo({url: '/path/to/page'})

Related interface 2

Only the following JSSDK interfaces are supported on the web page:

Interface module The interface description The specific interface
Determines whether the client supports js checkJSApi
The image interface Take a photo or upload it chooseImage
Preview the picture previewImage
Upload an image uploadImage
Download the picture downloadImage
Get a local picture getLocalImgData
The audio interface Start recording startRecord
Stop recording stopRecord
Listening to the recording stops automatically onVoiceRecordEnd
Play voice playVoice
Pause playback pauseVoice
Stop play stopVoice
Listening to speech onVoicePlayEnd
Upload interface uploadVoice
Download interface downloadVoice
Intelligent interface Identify audio translateVoice
Device Information Get a network status getNetworkType
Geographic location Use built-in map getLocation
Get a geographic location openLocation
Shake around the surrounding Open Ibeacon startSearchBeacons
Close Ibeacon stopSearchBeacons
Monitor iBeacon onSearchBeacons
WeChat sweep Tun up WeChat sweep scanQRCode
WeChat voucher Pull the list of vouchers used chooseCard
Add the voucher interface in bulk addCard
Check the voucher for the WeChat card bag openCard
Press and hold to identify Small program round code No
Related interface 3

When the user shares, they can get the URL of the current slt;web-view/sgt; that is, return the webViewUrl parameter in the onShareAppMessage callback.

Example code:

Page({
  onShareAppMessage(options) {
    console.log(options.webViewUrl)
  }
})
Related interface 4

Within a Web page, you can window.__wxjs_environment a small program environment by using a few variables.

Example code:

// web-view下的页面内
wx.ready(function() {
    console.log(window.__wxjs_environment === 'miniprogram') // true
})

Bug & Tip

  1. The domain name of iframe in the web page also needs to be configured to the domain name whitelist.
  2. On the developer tool, you can open the debugging of the component by right-click-debugging on the component.
  3. Only one page per page can be automatically rolled out and overwritten with other components.
  4. Communication other than the interface provided by JSSDK is not supported between web-view/gt; web pages and small programs.
  5. In iOS, if there is a case where the JSSDK interface call is unsysponsive, you can add a src after the src of the .lt;web-view/wechat_redirect solution.