• 请不要在回答技术问题时复制粘贴 AI 生成的内容
DeepUse
V2EX  ›  程序员

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

  •  
  •   DeepUse · May 13, 2021 · 2243 views
    This topic created in 1843 days ago, the information mentioned may be changed or developed.

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

    也就是说 canShare 已经弃了。
    DeepUse
        3
    DeepUse  
    OP
       May 13, 2021
    @no1xsyzy 认真的人,谢谢啊!
    ragnaroks
        4
    ragnaroks  
       May 13, 2021
    试了几个 chrome 的套壳浏览器,canShare() 总是返回 false,但 share() 是没问题的
    DeepUse
        5
    DeepUse  
    OP
       May 14, 2021
    @ragnaroks 谢谢你的经验
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2935 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 08:45 · PVG 16:45 · LAX 01:45 · JFK 04:45
    ♥ Do have faith in what you're doing.