V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
DeepUse
V2EX  ›  程序员

有谁用过 navigator.share()这个 api?

  •  
  •   DeepUse · 2021-05-13 09:51:28 +08:00 · 1513 次点击
    这是一个创建于 1050 天前的主题,其中的信息可能已经有所发展或是发生改变。

    Navigator.share https://developer.mozilla.org/zh-CN/docs/Web/API/Navigator/share

    if (navigator.canShare && navigator.canShare({ files: filesArray })) {
      navigator.share({
        files: filesArray,
        title: 'Pictures',
        text: 'Our Pictures.',
      })
      .then(() => console.log('Share was successful.'))
      .catch((error) => console.log('Sharing failed', error));
    } else {
      console.log(`Your system doesn't support sharing files.`);
    }
    

    分享 files 的时候,不支持 iOS 和 Mac?有谁深入使用过这个 API,可以交流一下吗?

    5 条回复    2021-05-14 12:47:44 +08:00
    wheelg
        1
    wheelg  
       2021-05-13 14:28:36 +08:00
    iOS safari 实验特性里可以开启 web share api
    no1xsyzy
        2
    no1xsyzy  
       2021-05-13 15:11:44 +08:00
    没用过也没苹果设备,但瞄了眼
    https://caniuse.com/mdn-api_navigator_canshare
    safari 上支持 share 但不支持 canShare
    看了下 w3c 的 spec 里面没有提到 canShare ; MDN 内指向 w3c 的链接失效,表示被移到前述的 w3c spec

    也就是说 canShare 已经弃了。
    DeepUse
        3
    DeepUse  
    OP
       2021-05-13 16:08:06 +08:00
    @no1xsyzy 认真的人,谢谢啊!
    ragnaroks
        4
    ragnaroks  
       2021-05-13 23:35:17 +08:00
    试了几个 chrome 的套壳浏览器,canShare() 总是返回 false,但 share() 是没问题的
    DeepUse
        5
    DeepUse  
    OP
       2021-05-14 12:47:44 +08:00
    @ragnaroks 谢谢你的经验
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5174 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 09:42 · PVG 17:42 · LAX 02:42 · JFK 05:42
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.