Javascript Safari剪贴板错误“;TypeError:undefined不是对象;

Javascript Safari剪贴板错误“;TypeError:undefined不是对象;,javascript,reactjs,safari,mobile-safari,Javascript,Reactjs,Safari,Mobile Safari,仅在safari浏览器中出现错误“TypeError:undefined不是对象(评估'navigator.clipboard.writeText')”。我正在传递我当前的链接。有什么问题吗 copyLink = e => { e.preventDefault(); console.log(document.location.href) navigator.clipboard .writeText(document.location.href)

仅在safari浏览器中出现错误“TypeError:undefined不是对象(评估'navigator.clipboard.writeText')”。我正在传递我当前的链接。有什么问题吗

 copyLink = e => {
    e.preventDefault();
    console.log(document.location.href)
    navigator.clipboard
      .writeText(document.location.href)
      .then(() => {
        this.setState({
          urlIsCopied: true
        });
      })
      .catch(e => console.error(e));
  };

你能看看这个插件吗。只需使用下面的代码,它的工作

copy('Text to Copy!');

希望这对你有帮助

Safari中此API的状态未知可能不受支持始终搜索是否可以在您需要支持的浏览器中使用该API(请检查不确定您需要的API是什么)。对于不支持API的浏览器,您需要不同的解决方案。