W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
當(dāng)使用 web-view 組件時,用戶從 A(h5) 頁面跳轉(zhuǎn)到了 B(h5) 頁面。此時,用戶在 B 頁面發(fā)起分享,更可能的預(yù)期是分享 B 頁面。但是,默認(rèn)行為將打開 A 頁面。此時,開發(fā)者可以做以下處理,讓分享后打開 B 頁面。
代碼示例
在開發(fā)者工具中打開
// swan 文件
<web-view s-if="webViewUrl" src="{{webViewUrl}}"></web-view>
// js 文件
Page({
data: {
webViewUrl: ''
},
onLoad({webViewUrl}) {
webViewUrl && this.setData({webViewUrl});
},
onShareAppMessage({webViewUrl}) {
return {
title: '分享回流示例',
content: '默認(rèn)會回到分享時的 url',
path: `/pages/openShare/openShare?webViewUrl=${encodeURIComponent(webViewUrl)}`
};
}
});
const webViewUrl = location.href;
swan.openShare({
title: '智能小程序示例',
content: '世界很復(fù)雜,百度更懂你',
appKey: 'y3dTfnWfkx2OXttMEMWlGHoB1KzMogm7', // 可通過 開發(fā)者平臺 -> 設(shè)置 -> 開發(fā)設(shè)置 中查看
path: `/pages/openShare/openShare?webViewUrl=${encodeURIComponent(webViewUrl)}`
});
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: