使用 Angular 复制到剪贴板,并将超链接隐藏在文本中

问题描述 投票:0回答:1

想要复制类似“ Google”的内容,当我将其粘贴到 Markdown 编辑器中时,它应该显示为 Google,这将是可点击的文本。

如何使用最新的剪贴板 API 将超链接复制到 Angular 中的剪贴板。

html angular clipboard copy-paste
1个回答
0
投票

您可以使用的示例方法:

 copyGoogleLinkMarkupToClipboard(): void {
    const textArea = document.createElement("textarea");
    textArea.value = "<a href='https://www.google.com'>Google</a>";
    document.body.appendChild(textArea);
    textArea.focus();
    textArea.select();
    try {
      document.execCommand('copy');
    } catch (err) {
      alert('unable to write to clipboard');
    }
    document.body.removeChild(textArea);
   
  }
© www.soinside.com 2019 - 2024. All rights reserved.