0
I am trying to save the html code changes on my page made by an interaction of Java. More precisely I want the table I create with js to keep saved the changes in html.
localStorage.setItem("resposta", document.querySelector("#tabela-anagrama"));
localStorage.getItem("resposta")
When I do a console.log to see what’s saved in localStorage the answer is [Object Htmltablerowelement]
My question is the following how do I save the html code and make when I update the page the table comes back already with the saved changes?
Depending on the content sometimes the
localStoage
do not correctly save the content because it seems convert to String, and send as Base64localStorage.setItem("resposta",btoa(document.querySelector("#tabela-anagrama").outerHTML));
then to recover:atob(localStorage.resposta);
?– RpgBoss
@Rpgboss The problem that the
base64
is almost always bigger than the code itself and also it is aString
. I did a test with the table above, and no errors occurred. But I added the disadvantage of the storage limit (I believe it will not have errors cause it).– Valdeir Psr
It really makes a lot of sense, so in the end I think it doesn’t even pay to save the HTML content, only the values and content, I don’t know what happens if there are too many line breaks.
– RpgBoss