【发布时间】:2019-05-10 23:02:37
【问题描述】:
我正在尝试在我的测试网络应用程序上实现 Web Share Api 功能,但我似乎无法做到。这是代码:
const newVariable: any = navigator;
{newVariable && newVariable.share && <IconButton aria-label="Share" onClick={async (e) => {
try {
const id = await shareRepository.shareTrip(this.props.todolist)
const url = "https://something.com/share/" + id
await newVariable.share({
title: 'Check my todolist for ' + this.props.todolist.trip.departure + ' - ' + this.props.todolist.trip.arrival,
text: 'Check my todolist for ' + this.props.todolist.trip.departure + ' - ' + this.props.todolist.trip.arrival,
url: url,
})
} catch (error) {
alert(error)
}
}}>
<ShareIcon />
</IconButton>}
每次我在 Firefox 和 iOS 版 Safari 上尝试时,都会收到一条错误消息:
NotAllowedError:当前上下文中用户代理或平台不允许该请求,可能是因为用户拒绝了权限。
如果在这些浏览器上我尝试从 google.com 共享某些内容,我会得到本机对话框来选择要与哪个应用共享。
我不明白为什么。此页面上没有关于权限的讨论:https://developers.google.com/web/updates/2016/09/navigator-share
更新:
在 Chrome for android 上运行正常,在 Firefox for Android 上不起作用。在 Chrome、Firefox 和 Safari 上(我相信它们都使用了 safari 引擎这三个)只有在我通过 "" 这意味着页面本身或 "https://something.com/share/" 时才会工作,如果我通过 "https://something.com/share/"+id 就会中断:/
【问题讨论】:
-
在搜索时,我遇到了关于网络共享功能的非常简单的演示:mkonikov.com/web-share-testing,它适用于我的 Chrome@Android。你能在你得到 NotAllowedError 的浏览器上检查一下吗?
-
如果我用
''更改我的网址,即使我的代码也有效。但我不明白我的网址有什么问题 -
它是否与托管代码的域匹配?
-
@skyboyer 我写了一个更新,基本上:在 Chrome for android 上工作正常,在 Firefox for Android 上不起作用。在 Chrome、Firefox 和 Safari 上(我相信它们都使用 safari 引擎这三个)只有在我通过
""时才有效,这意味着页面本身,或者"https://something.com/share/",如果我通过"https://something.com/share/"+id:/ -
这是一个 Safari 错误:stackoverflow.com/questions/56046434/…
标签: javascript