可以在嵌入式网站中使用一个按钮。为什么?

发布于 2025-02-11 16:53:10 字数 718 浏览 0 评论 0原文

我已经将网站纳入了另一个网站使用iframe。 < iframe src = ..“> .. 在嵌入式网站内部有一个复制按钮。当我在网站(无嵌入)中使用它时,它可以正常工作。但是当我在iframe中使用它时,它不会..

我的按钮代码: < button onClick =“ copy()”> copy</button> JS:

function copy() {
  let copyText = document.getElementById("resu");
  
  copyText.select(); 
  copyText.setSelectionRange(0, 99999); /* For mobile devices */

  navigator.clipboard.writeText(copyText.value.replace(/A  /, "A ")).then(function() {
  alert("Copied to clipboard.");
}, function(err) {
  alert("Could not copy text.");
});
  }

怎么了?


edit :通过使用< iframe src =“ ..”允许=“剪贴板 - 读取; clipboard-write;”> ..感谢

I have embedded an website inside another website using iframe..
<iframe src=..">..
Inside the embedded website there is a copy button. When I use it in website(without embed) it works. But when I use it in iframe it doesn't..

My button code:
<button onclick="copy()">copy</button>
Js:

function copy() {
  let copyText = document.getElementById("resu");
  
  copyText.select(); 
  copyText.setSelectionRange(0, 99999); /* For mobile devices */

  navigator.clipboard.writeText(copyText.value.replace(/A  /, "A ")).then(function() {
  alert("Copied to clipboard.");
}, function(err) {
  alert("Could not copy text.");
});
  }

What's wrong??


Edit: This problem was solved by using <iframe src=".." allow="clipboard-read; clipboard-write;"> .. Thanks❤️

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文