I'm building a site for my org that generates templates for users
I am able to copy a chosen template to the user's clipboard like so:
function copyTemplateText(){
let text_to_copy = document.getElementById("templateText").innerHTML;
if (!navigator.clipboard){
// Pass
} else{
navigator.clipboard.writeText(text_to_copy).then(
function(){
console.log('copied'); // success
})
.catch(
function() {
console.log('not copied');// fail
});
}
This template would need to be pasted into the text area of an external website. Granted, users just need to CTRL+V and be done with it, but I was wondering if this can be done automatically. How can I pass a function from my site, to this new one? Is this possible?
Pseudo Code:
copyTemplateText('..runs');
let pasteHere = document.getElementByID('textBox');
pasteHere.innerText = What's in the clipboard;
I tried doing it with sessionStorage:
navigator.clipboard.readText().then(clipText =>
sessionStorage.setItem("clipboard", clipText));
let pasteHere = document.getElementById("textBox");
pasteHere.innerText = sessionStorage.getItem("clipboard");
But that doesn't work. I get:
Uncaught TypeError: Cannot set properties of null (setting 'innerText || innerHTML')
at HTMLAnchorElement.pasteTicketTemplate
Uncaught (in promise) DOMException: Document is not focused.
Is what I'm trying to do feasible? If so, how would I go about this?
Thanks a bunch!