什么会阻止Javascript将值存储在剪贴板上?

什么会阻止Javascript将值存储在剪贴板上?,javascript,asp.net,google-chrome,firefox,clipboard,Javascript,Asp.net,Google Chrome,Firefox,Clipboard,我正在我的ASP.Net网站中使用一些简单的Javascript 一个值被计算并存储在一个隐藏的文本框中,如下所示 <asp:LinkButton ID="LinkButtonShare" runat="server" CssClass="btn btn-success" OnClientClick="copyToClipboard()"><i class="fa fa-share-square"></i> Share</asp:LinkButton&g

我正在我的ASP.Net网站中使用一些简单的Javascript

一个值被计算并存储在一个隐藏的文本框中,如下所示

<asp:LinkButton ID="LinkButtonShare" runat="server" CssClass="btn btn-success" OnClientClick="copyToClipboard()"><i class="fa fa-share-square"></i> Share</asp:LinkButton>
<div class="hidden"><asp:TextBox ID="TextBoxCopyURL" runat="server" ClientIDMode="Static"></asp:TextBox></div>
function copyToClipboard() {
  var copyText = document.getElementById("TextBoxCopyURL");
  copyText.select();
  document.execCommand("copy");

  /* Alert with the copied text */
  alert("Copied the text: " + copyText.value);
导致出现如下警报,但该字符串从未复制到Firefox或Chrome中的“我的剪贴板”


我似乎无法理解我在这么简单的事情上遗漏了什么

代码略有变化,但基本相同。它按预期工作


请注意,在js中无法直接获取剪贴板的内容。i、 e.您不能以编程方式触发粘贴或访问剪贴板的内容。

代码略有变化,但基本相同。它按预期工作


请注意,在js中无法直接获取剪贴板的内容。i、 e.您不能以编程方式触发粘贴或访问剪贴板的内容。

遵循本页的示例:

您可以通过以下方式解决此问题:

function copyToClipboard() {
    var copyText = document.getElementById("TextBoxCopyURL");
    copyTextValue = copyText.value;

    window.clipboardData.setData('Text' , copyTextValue );

    /* Alert with the copied text */
    alert("Copied the text: " + copyTextValue );

}

以下是本页上的示例:

您可以通过以下方式解决此问题:

function copyToClipboard() {
    var copyText = document.getElementById("TextBoxCopyURL");
    copyTextValue = copyText.value;

    window.clipboardData.setData('Text' , copyTextValue );

    /* Alert with the copied text */
    alert("Copied the text: " + copyTextValue );

}