javascript - How to have separate sessionStorages for iframes on same origin -


the standard w3c standard says localstorages:

different authors sharing 1 host name, example users hosting content on geocities.com, share 1 local storage object. there no feature restrict access pathname. authors on shared hosts therefore urged avoid using these features, trivial other authors read data , overwrite it.

but sessionstorages it's said provide separate sessionstorages tabs , windows same origin.

but seems iframes share sessionstorage.

is there way have separate sessionstorages on via iframes on same origin.

edit: since there confusion if tabs/windows have separate sessionstorages, here sample page. save code in file , open 2 different tabs. refresh 1 tab 5 times , refresh other tab 1 time. you'll see numbers differ.

<!doctype html> <html> <body>     <div id="result"></div>     <script>         sessionstorage.setitem("counter", (parseint(sessionstorage.getitem("counter"), 10) || 0 ) + 1);         document.getelementbyid("result").innerhtml = sessionstorage.getitem("counter");     </script> </body> </html> 

edit2: have tried far use iframe sandbox attribute. got error within iframe , cann't use sessionstorage @ all. had add sandbox="allow-same-origin". sessionstorage same in iframes again.

thanks in advance.

@adeneo correct when indicating

the storage container set origin domain, , iframes same origin share same object, if iframe opens new session

a workaround not appear exist

<!doctype html> <html> <body>     <iframe name="one" src="sessionstoragetest.html"></iframe>     <iframe name="two" src="sessionstoragetest1.html"></iframe> </body> </html> 

sessionstoragetest.html

<!doctype html> <html> <body>     <div id="result"></div>     <script>         sessionstorage.setitem("counter", (parseint(sessionstorage.getitem("counter"), 10) || 0 ) + 1);         document.getelementbyid("result").innerhtml = sessionstorage.getitem("counter");     </script> </body> </html> 

sessionstoragetest1.html

<!doctype html> <html> <body>     <div id="result"></div>     <script>         var = 0;           while (++i < 10) {             sessionstorage.setitem("counter", (parseint(sessionstorage.getitem("counter"), 10) || 0 ) + 1);             document.getelementbyid("result").innerhtml = sessionstorage.getitem("counter");           }     </script> </body> </html> 

demonstrated @ plnkr http://plnkr.co/edit/etel4toabm6gwow6qae5?p=preview


Comments

Popular posts from this blog

ios - UITEXTFIELD InputView Uipicker not working in swift -

Hatching array of circles in AutoCAD using c# -