在移动Safari的私有模式下,不会在选项卡之间共享localStorage [英] localStorage is not shared across tabs in the private mode in mobile Safari

查看:158
本文介绍了在移动Safari的私有模式下,不会在选项卡之间共享localStorage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在移动Safari的私有模式下成功地将内容放入 localStorage 中.而且,如果我在2个不同的选项卡中打开Web应用程序,则它们将无法访问相同的 localStorage .就是说,我的意思是,如果我在第一个选项卡中设置了一个值,那么我在第二个选项卡中的应用程序将看不到它.这也可能在其他浏览器的私有模式下发生,但我没有机会对其进行测试.

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.

是否有 localStorage 的替代解决方案,或者在私有模式下是不可能的?

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

推荐答案

您可以 AJAX PHPMySQL 使用MySQL进行PHP检索.如果此数据需要特定于设备,则可以使用PHP使用 $ _ SERVER ['REMOTE_ADDR'] 来获取用户的IP地址,并将数据与其数据库中的IP关联,但请注意,IP如果用户更改网络,则可以更改.

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.

这篇关于在移动Safari的私有模式下,不会在选项卡之间共享localStorage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆