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

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

问题描述

我有一个简短的问题.当我按下按钮时,我想在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/NotAllowed错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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