document.execCommand()无法粘贴已渲染的html。

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

我正在开发一个将HTML内容复制到剪贴板的功能。如果我把这些存储在剪贴板上的数据粘贴到所见即所得的编辑器中,我得到的只是纯HTML代码。我需要的是一个渲染的链接。

这就是我的功能。

public copyLink(text, linkid) {

    const dummy = document.createElement('textarea');

    document.body.appendChild(dummy);
    dummy.value = '<a href="' + linkid + '">' + text + '</a>';
    dummy.select();
    document.execCommand('copy');
    document.body.removeChild(dummy);

    this.snackBar.open('in Zwischenablage kopiert', 'close', {
      duration: 2000,
    });
}

这里是在一个普通的所见即所得编辑器中粘贴后的视图。第一行是发生了什么,第二行是我需要的。

enter image description here

那么如何控制编辑器或浏览器的渲染行为?

javascript html wysiwyg
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.