简体   繁体   中英

is it possible to keep data while browser is open

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

this will keep data until tab is closed.

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

this will keep data forever (if user doesn't clear them).

I need some storage keeping data while browser is open.
So if a tab is closed I need that data on another tab, but clear them automatically when browser is closed.

Is it possible?

See 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.

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