Attribute | Type | Default value | Description |
src | string | - | The webview points to a webpage link. The webpage requires configuration of the business domain after logging into the TMF Mini Program Management Backend. |
bindload | eventhandler | - | When a webpage posts a message to the mini program, it triggers and receives messages at specific times (when the mini program backs out, the component is destroyed, or shared). e.detail = { data }, where data is an array composed of parameters from multiple postMessage instances. |
binderror | eventhandler | - | This event is triggered when the webpage loads successfully. e.detail = { src } |
binderror | eventhandler | - | This event is triggered when the webpage fails to load. e.detail = { src } |
<!-- wxml --><web-view src="https://www.qq.com/"></web-view>
web-view
, the interface provided by JSSDK can be used to return to the mini program page. The supported interfaces include:Interface Name | Description |
wx.miniProgram.navigateTo | The parameters are consistent with the mini program interface. |
wx.miniProgram.navigateBack | The parameters are consistent with the mini program interface. |
wx.miniProgram.switchTab | The parameters are consistent with the mini program interface. |
wx.miniProgram.reLaunch | The parameters are consistent with the mini program interface. |
wx.miniProgram.redirectTo | The parameters are consistent with the mini program interface. |
wx.miniProgram.postMessage | Sending a message to the mini program will trigger the component's message event at the following specific times: when the mini program is backed out, when the component is terminated, when sharing, and when copying the link. |
wx.miniProgram.getEnv | Obtaining the current environment |
<!-- html --><script type="text/javascript" src="https://qqq.gtimg.cn/miniprogram/webview_jssdk/qqjssdk-1.0.0.js"></script>
wx.miniProgram.navigateTo({url: '/path/to/page'})wx.miniProgram.postMessage({ data: 'foo' })wx.miniProgram.postMessage({ data: {foo: 'bar'} })wx.miniProgram.getEnv(function(res) { console.log(res.miniprogram) })
<web-view>
URL can be obtained, that is, the webViewUrl
parameter is returned in the onShareAppMessage
callback.Page({onShareAppMessage(options) {console.log(options.webViewUrl)},})
window.__wxjs_environment
variable can be used to determine whether it is in a mini program environment. It is recommended to use it in the WeixinJSBridgeReady
callback, or the getEnv
interface provided by JSSDK can also be used.// Within the web-view pagefunction ready() {console.log(window.__wxjs_environment === 'miniprogram') // true}if (!window.QQJSBridge || !QQJSBridge.invoke) {document.addEventListener('WeixinJSBridgeReady', ready, false)} else {ready()}// Orwx.miniProgram.getEnv(function(res) {console.log(res.miniprogram) // true})
Was this page helpful?