javascript - 我可以在 Safari 上使用 Web Share API 共享文件吗

标签 javascript web safari mobile-safari navigator

我正在尝试使用以下代码与 Web Share API Level 2 共享文件:

var file = new File(["foo"], "foo.txt", {
    type: "text/plain",
});

window.navigator.share({
    text: "Share text",
    title: "Share title",
    files: [file]
})

不幸的是,文件没有与 iPhone 共享,但在 Android 上成功共享。

有什么解决办法吗?

提前致谢。

最佳答案

我得到了文件共享工作。但在 Whatsapp + iOS 上,它仅在文本和标题内容为空时才有效(仅发送文件)。

  let data = {};
  if (files.length > 0) {
    data.files = files;
  }
  if (title !== '')
    data.title = title;
  if (text !== '')
    data.text = text;
  if (url !== '')
    data.url = url;

  error.textContent = '';
  navigator.share(data)
    .then(() => {
  })
    .catch((err) => {
    console.log('Unsuccessful share');
    error.textContent = 'Share failed: ' + err.message;
  });
https://jsfiddle.net/2q36fhb9/1/

关于javascript - 我可以在 Safari 上使用 Web Share API 共享文件吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60302475/

相关文章:

javascript - 如何更改 Safari 自动填充黄色背景颜色

html - 在 div 中居中文本,div 在 Safari 中不显示

iphone - 在 iPhone Mobile Safari 中单指滚动内部内容(div/iframe)

Javascript - eval 函数字符串内的加号

java - 在 UriComponentsBuilder 中使用 Expand() 和直接添加值有什么不同?

Web 可访问性和 h1-h6 标题 - 所有内容都必须在这些标签下吗?

testing - 为什么 PhantomCSS 移动 HTML 元素?

javascript - 用极坐标画正方形

javascript - 在 react 中将数据添加到字典

javascript - 页面加载后依次加载多个JS文件