0
How to edit an existing item in localStorage on an HTML blob page?
The item comes from another page and is replaced on the blob page, but when you try to replace it, you end up creating a new one accessible only inside the blob page, it is not possible to access it outside the blob page, not even by the browser console, I searched on this and found nothing informing this limitation of the blob.
You can edit the item outside the blob page with the same domain?
Example link in codepen: https://codepen.io/markvaaz/pen/LYYZgYE
//cria um item no localStorage (Ainda em um pagina comum)
localStorage.setItem("test", "not working")
//cria uma url blob
function newBlob(text){
var blob = new Blob(["\ufeff", text], {type: "text/html"})
var url = window.URL.createObjectURL(blob)
return url
}
//da um conteúdo para o blob e entra na url blob retornada
window.location.href = newBlob(`<button onclick="localStorage.setItem('test', 'working')">Click here to replace the item</button>`)
//a função do botão é substituir o item que foi criado anteriormente com um novo conteúdo, porém acaba criando um novo item acessivel apenas dentro da pagina blob, não é possivel acessar o item no console do navegador.
even if the blob is in the same domain as a normal page? as for example in codepen the domain
https://cdpn.io/...
nextblob:https://cdpn.io/cd18b45a-84ea-4a2b-9cad-3bb488d0f28f
– Mark Vaaz
@Markvaaz in codepen the origin of the document does not change. Every time you change the code it changes only the end of the
src
iframe:https://cdpn.io/boomboom/v2/index.html?key=iFrameKey-XXXXX
the source address of the document remains unchanged. In this case, as the origin is the same,localStorage
works using its logic. Every time the source is changed thelocalStorage
will have a new instance associated with the origin.– Marcelo Vismari
In this case, it does not work in codepen, and actually the iframe src does not change, but as you pass a new address it becomes the new iframe address.
– Mark Vaaz
@Markvaaz just opened your link in codepen and is working correctly. By clicking the value
working inside the blob
is displayed onbody.innerHTML
. If you remove the sectionlocalStorage.setItem('test', 'working inside the blob ');
"not Working" will appear. Note that localStorage is the same before and after the click since the origin of the document has not changed. If you can, detail a little more please your question if it has not been clear– Marcelo Vismari
@Markvaaz only complementing, the origin of the
src
iframe keeps. Englobe your script with a setTimeout of a 2s and right in the first line outside of setTimeout printe the address. You will see something like: https://cdpn.io/boomboom/v2/index.html?key=iFrameKey-edca7c65-9f25-598b-56cf-f3ea718d9a4e and after 2s blob:https://cdpn.io/c42af343-2b6b-4679-996e-78c71a97c2d3– Marcelo Vismari