localStorage is not shared across tabs in the private mode in mobile Safari

烂漫一生 提交于 2021-02-11 14:32:27

问题


I can successfully put stuff into the localStorage in the private mode of mobile Safari. And if I open my web app in 2 different tabs, they don't have access to the same localStorage. By that, I mean if I set a value in the 1st tab, my app in the 2nd tab can't see it. This might happen in other browsers' private mode too but I haven't got a chance to test them.

The same code works fine if it is not private mode. The value set by the 1st tab can be accessed by the 2nd tab.

Is there an alternate solution to localStorage or it is just impossible in the private mode?


回答1:


You could connect to a back-end server and store your data in a database, but private mode is specifically meant to block cookies and forms of local storage, so you cannot reliably store your data across tabs in the frontend. Users know this, and they don't expect accounts to stay logged in or anything of the like. That being said, if your function seems like something users would expect to still be able to use it across tabs, invest the time to check out AJAX, PHP insertion with MySQL, and PHP retrieval with MySQL. If this data needs to be device-specific, you can grab the user's ip address with PHP using $_SERVER['REMOTE_ADDR'] and associate the data with their IP in your database, but be aware that IPs can change if the user changes networks.



来源:https://stackoverflow.com/questions/59587465/localstorage-is-not-shared-across-tabs-in-the-private-mode-in-mobile-safari

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!