Share feedback, ideas and get community help

Updated 7 months ago

copy variable to workspace

Hi everyone, good afternoon.

I'm running a chat here and saving the bot's response in the response variable

Then I show a button on the screen that runs the following script

var resposta = {{resposta}};

function copyToClipboard() {
var textToCopy = resposta;
var tempInput = document.createElement("textarea");
tempInput.value = textToCopy;
document.body.appendChild(tempInput);
tempInput.select();
document.execCommand("copy");
document.body.removeChild(tempInput);
alert(resposta);
}

console.log(resposta);


However, instead of saving the content of the response variable to the work area, it saves all the code to the work area.

What am I doing wrong?
B
1 comment
Maybe a script like this instead?

Plain Text
const originalText = "Original Text"
const boldText = "<b>"+originalText+"</b>";
const blobHtml = new Blob([boldText], { type: "text/html" });
const blobText = new Blob([originalText], { type: "text/plain" });
const data = [new ClipboardItem({
    ["text/plain"]: blobText,
    ["text/html"]: blobHtml,
})];

navigator.clipboard.write(data).then(
    () => {alert('success html copy')},
    () => {}
);


https://stackoverflow.com/questions/74838274/copy-html-rich-text-using-navigator-clipboard
Add a reply
Sign up and join the conversation on Discord