欢迎光临
我们一直在努力

九八云百度小程序教程:web-view 中的分享

  • web-view 中的分享
    • 代码示例

    web-view 中的分享

    当使用 web-view 组件时,用户从 A(h5) 页面跳转到了 B(h5) 页面。此时,用户在 B 页面发起分享,更可能的预期是分享 B 页面。但是,默认行为将打开 A 页面。此时,开发者可以做以下处理,让分享后打开 B 页面。

    • 针对小程序框架调起的分享

    代码示例

    在开发者工具中打开

    在开发者工具中打开

    在 WEB IDE 中打开

    • SWAN
    • JS
    
     
    1. <web-view s-if="webViewUrl" src="{{webViewUrl}}"></web-view>
    
     
    1. Page({
    2. data: {
    3. webViewUrl: ''
    4. },
    5. onLoad({webViewUrl}) {
    6. webViewUrl && this.setData({webViewUrl});
    7. },
    8. onShareAppMessage({webViewUrl}) {
    9. return {
    10. title: '分享回流示例',
    11. content: '默认会回到分享时的 url',
    12. path: `/pages/openShare/openShare?webViewUrl=${encodeURIComponent(webViewUrl)}`
    13. };
    14. }
    15. });
    • 针对 H5 页面通过 openShare API 调起的分享

    • JS

    
     
    1. const webViewUrl = location.href;
    2. swan.openShare({
    3. title: '智能小程序示例',
    4. content: '世界很复杂,百度更懂你',
    5. // 可通过 开发者平台 -> 设置 -> 开发设置 中查看
    6. appKey: 'y3dTfnWfkx2OXttMEMWlGHoB1KzMogm7',
    7. path: `/pages/openShare/openShare?webViewUrl=${encodeURIComponent(webViewUrl)}`
    8. });

    赞(0) 打赏
    未经允许不得转载:九八云安全 » 九八云百度小程序教程:web-view 中的分享

    评论 抢沙发