Javascript/剪贴板 API/Safari iOS/NotAllowedError 消息 [英] Javascript / Clipboard API / Safari iOS / NotAllowedError Message

查看:33
本文介绍了Javascript/剪贴板 API/Safari iOS/NotAllowedError 消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简短的问题.当我按下一个按钮时,我想在我的 iOS 设备上的剪贴板中添加一个文本,该按钮使用 ajax 请求将数据放入剪贴板.

I have a short Problem. I want to add a text to the clipboard on my iOS Device when I press a Button which use a ajax request to get the data into the clipboard.

在我的桌面和我的 Android 设备上使用浏览器时,它运行良好,但在我的 iOS 设备上出现问题.

With the Browser on my Desktop and my Android device it works very well but with my iOS Device a get an Issue.

$.ajax({
            type: "GET",
            url: "missing_string.php",
            data: getAttributes($(this)),
            success: function(data) {
                if (navigator.clipboard) {
                    navigator.clipboard.writeText(data)
                        .then(() => {
                            alert("SUCCESS");
                        })
                        .catch(err => {
                            alert(err);
                            console.log('Something went wrong', err);
                        });

所以我收到以下错误消息:

So I get following error message:

NotAllowedError:当前上下文中用户代理或平台不允许该请求,可能是因为用户拒绝了权限.

NotAllowedError: the request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.

如何将我的文本放入剪贴板?我使用 iOS 13.5 和 13.4 应该支持剪贴板 API.

How can I get my Text to the clipboard? I use iOS 13.5 and 13.4 should support the Clipboard API.

推荐答案

https://webkit.org/blog/10247/new-webkit-features-in-safari-13-1/

Async Clipboard API
WebKit brings the Async Clipboard API to this release of Safari...

you should read it

TLDR:该实现可通过 navigator.clipboard API 获得,该 API 必须在用户事件中调用

TLDR: The implementation is available through the navigator.clipboard API which must be called within user events

您尝试复制到剪贴板作为 API 调用的结果,而不是在用户交互的上下文中.这是不允许的.

You are trying to copy to the clipboard as a result of an API call instead of in the context of a user interaction. This is not allowed.

这篇关于Javascript/剪贴板 API/Safari iOS/NotAllowedError 消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆