百度智能小程序 web-view中的分享

2020-09-05 14:45 更新

web-view 中的分享

當(dāng)使用 web-view 組件時,用戶從 A(h5) 頁面跳轉(zhuǎn)到了 B(h5) 頁面。此時,用戶在 B 頁面發(fā)起分享,更可能的預(yù)期是分享 B 頁面。但是,默認(rèn)行為將打開 A 頁面。此時,開發(fā)者可以做以下處理,讓分享后打開 B 頁面。

  • 針對小程序框架調(diào)起的分享

代碼示例 
在開發(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)}`
        };
    }
});
  • 針對 H5 頁面通過 openShare API 調(diào)起的分享
const webViewUrl = location.href;
swan.openShare({
    title: '智能小程序示例',
    content: '世界很復(fù)雜,百度更懂你',
    appKey: 'y3dTfnWfkx2OXttMEMWlGHoB1KzMogm7', // 可通過 開發(fā)者平臺 -> 設(shè)置 -> 開發(fā)設(shè)置 中查看
    path: `/pages/openShare/openShare?webViewUrl=${encodeURIComponent(webViewUrl)}`
});


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號