gpt4 book ai didi

javascript - 浏览器打开时是否可以保留数据

转载 作者:行者123 更新时间:2023-12-03 01:49:06 24 4
gpt4 key购买 nike

sessionStorage.setItem('img', $('#cpimgt').attr('src'));

这将保留数据直到选项卡关闭。

localStorage.setItem('img', $('#cpimgt').attr('src'));

这将永远保留数据(如果用户不清除它们)。

我需要一些存储空间来在浏览器打开时保存数据。
因此,如果关闭一个选项卡,我需要另一个选项卡上的数据,但当浏览器关闭时会自动清除它们。

可能吗?

最佳答案

参见https://security.stackexchange.com/questions/49636/can-a-webpage-read-another-pages-cookies

Yep this is defended against using the same origin policy, which generally prevents one site reading anothers cookies.

When you see behaviour where adverts seem to know where you've been it's likely due to 3rd party ad tracking cookies.

So as a simplified example if you go to site A which uses an ad network, that ad network can record that you were on that site by placing a tracking cookie on your PC.

Then when you go to Site B which uses the same ad network, the ad network reads the cookie that was set when you were on Site A (which it can do 'cause it's loading content from it's domains in both cases so it doesn't break same origin) and can then offer you adverts based on your browsing habits.

关于javascript - 浏览器打开时是否可以保留数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50495928/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com