简体   繁体   中英

localStorage.clear() in Iframe also clear the localStorage of Main Page

I am working on Live Editor and use a HTML5 localstorage to store some important data,on my Main Page ,

And I have an Iframe on my Main Page that is working on same domain which is used to show the result of editor, Here the problem is, whenever i write the JS code :

Like :

localStorage.clear();

To my editor and run it on my Iframe then it also clear my localStorage of Main Page.

How i Correct this problem ?

I am sending my code to iframe by using string,

iframe.contentWindow.document.head.appendChild(Script);

Script contains a script tag with the User Code and it will run only inside iframe! But Why my localStorage.clear(); also clear Stored data of Main Page ?

Answer Will really appreciated !!

It's more or less anwsered here:

In HTML5, is the localStorage object isolated per page/domain?

localStorage is per domain.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM