Is there a way to create a copy to clipboard button in Sidebar using Google's Apps Script
?
My current code is the following, but the copy button is not working:
function createCalendarEvent() {
var html = HtmlService.createHtmlOutput()
.setTitle("Πληροφορ?ε? για Ημερολ?γιο")
.setContent('<div><p id="item-to-copy">Test</p>' + '
<button onclick='+"copyToClipboard()"+'>Copy</button></div>')
var ui = SpreadsheetApp.getUi(); // Or DocumentApp or SlidesApp or FormApp.
ui.showSidebar(html);
}
function copyToClipboard() {
const str = document.getElementById('item-to-copy').innerText;
const el = document.createElement('textarea');
el.value = str;
el.setAttribute('readonly', '');
el.style.position = 'absolute';
el.style.left = '-9999px';
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
}
The second function is javascipt.
Can you help me please?
Edit
When I click F12 on the browser, I get the following error:
Uncaught ReferenceError: copyToClipboard is not defined
at HTMLButtonElement.onclick (userCodeAppPanel:1)
onclick @ userCodeAppPanel:1
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…