So let’s say i have data in localStorage and there’s 25 different names. How do i copy and paste that localStorage data via clipboard by clicking buttons.
This is the code of button that needs to copy localStorage data:
<a href="" onclick="copyjson()"><div id="Shape1"><div id="Shape1_text"><span style="color:#303C49;font-family:Arial;font-size:16px;"><strong>Скопировать данные</strong></span></div></div></a>
I tried to copy using js code, but somehow it only run if i run that through console:
function copyjson() {
copy(JSON.stringify(localStorage));
}
2
Answers
The
copy
function is only used for debugging on console, and isn’t actually a function that you can use in scripts (you will see that if you try to access it viawindow.copy
).Take a look at the Clipboard API and specifically to the .write method.
You need something like this: