网站如何记住你对它的偏好(以及关于cookies的选择)?

网站如何记住你对它们的偏好(或者不想要),以及cookies本身的敏感主题呢?今天的超级用户问答旨在为困惑的读者解释cookies的工作原理和它们存储的信息。...

网站如何记住你对它的偏好(以及关于cookies的选择)?

网站如何记住你对它们的偏好(或者不想要),以及cookies本身的敏感主题呢?今天的超级用户问答旨在为困惑的读者解释cookies的工作原理和它们存储的信息。

今天的问答环节是由SuperUser提供的,SuperUser是Stack Exchange的一个分支,是一个由社区驱动的问答网站分组。

图片由Pedro Vezini(Flickr)提供。

问题

超级用户读者Ruud Lenders想了解更多关于网站偏好和cookies的工作原理:

A pop-up displayed on a website that I visited and asked me if I would allow the website to store preferences in cookies. By accident, I chose no. Refreshing the page does not bring the pop-up back. Is there a way to get this kind of pop-up back without clearing the history and cookies?

This also got me to thinking. How can a website remember if it is allowed to store cookies? By storing it in a cookie?

网站如何记住你对它的总体偏好,以及你对cookies的总体选择?

答案

超级用户贡献者bvukelic为我们提供了答案:

They asked you if you would like to store preferences in cookies, not if you would like them to set cookies in general. So if I were writing support for this feature, I would set a separate cookie (nopref) and check whether or not the user has this cookie. There is a good chance you will find such a cookie for that website, which you can clear without removing other cookies or history.

Inspecting Cookies Set for a Particular Page

In Firefox, you can list cookies for a particular web page by right-clicking a blank part of the page, then selecting the View Page Info option. You will find a View Cookies button in the Security Tab. In Chrome, you have the same View Page Info option which opens a dialog that hangs from the address bar. A link near the top will take you to a listing of cookies. I assume similar features can be found in other browsers.

Discovering if a Website Sets a Cookie

Here is one way that you can discover what the website is doing. Visit the website in Incognito Mode. Open the Developer Tools and switch to the Network Tab. Then check to see what activity is occurring in the background as you decline having the site track you with cookies. Specifically, look for resp***e headers and see if there are any Set-Cookie headers in there. Then try deleting cookies mentioned in the header to see if that makes any difference.

About localStorage

Since another poster has mentioned localStorage (in-browser database), I will comment on this as well. I think it will be very rare that a website uses localStorage for this purpose as localStorage data is not accessible to the server unless there is JavaScript code that sends the data back to the server. If you wish to check the contents of localStorage, the fastest way is to open the Developer Tools in your browser, go to the (JavaScript) C***ole Tab, and type localStorage. This should give you an output that looks something like:

  • Storage { someKey: “value”, length: 1 }

The someKey identifies the value set by JavaScript on the web page you are on. If you believe someKey does something relevant, you can try removing it by running the following:

  • localstorage.removeItem(‘someKey’);

This removes the data under someKey from localStorage, and reloading the web page may restore it to factory settings. If you are not sure the particular key is set by the cookie notification functionality, you may open the web page in Incognito Mode and list the contents of localStorage before interacting with the web page.

Again, I doubt many websites use localStorage for this purpose.


有什么要补充的解释吗?在评论中发出声音。想从其他精通技术的Stack Exchange用户那里了解更多答案吗?在这里查看完整的讨论主题。

  • 发表于 2021-04-11 07:03
  • 阅读 ( 197 )
  • 分类:互联网

你可能感兴趣的文章

关于谷歌chrome的新cookies政策,你需要知道的一切

... 然后,cookies将信息提供给网站运营商。此信息可提高网站加载速度,管理与设备相关的崩溃报告,并跟踪密码。此外,cookies将搜索链接到您的Google帐户,以改进用于提供广告的预测性建议。 ...

  • 发布于 2021-03-10 20:45
  • 阅读 ( 289 )

如何清除chrome中的Cookie和cache

您在使用Chrome访问桌面或**上的网站时遇到问题吗?你的cookies和缓存文件可能是罪魁祸首。去掉这些文件,然后看看Chrome的性能是否更好。 ...

  • 发布于 2021-03-11 11:15
  • 阅读 ( 241 )

谷歌chrome常见问题解答

...到正确的主页?也许一个新的标签扩展或互联网上最好的网站之一就足够了。 ...

  • 发布于 2021-03-12 03:38
  • 阅读 ( 283 )

23个网站的权限在谷歌chrome中更改,以便更好地浏览

...也有一长串你可以切换的权限吗?这使您可以更好地控制网站如何与您的设备交互。让我们看看可用的浏览器权限,并考虑应该如何处理它们。 ...

  • 发布于 2021-03-19 02:23
  • 阅读 ( 321 )

facebook正在跟踪你!下面是如何阻止它

...系统,也会在离线追踪你。但是像Facebook这样的社交媒体网站呢? ...

  • 发布于 2021-03-19 14:26
  • 阅读 ( 316 )

chrome os和google chrome的7项基本隐私设置

...意味着谷歌可以看到你搜索的所有内容和你访问的每一个网站,无论你是否使用谷歌搜索引擎,即使你改变主意,决定不访问某个网站或开始搜索。你对谷歌了解你这么多感到满意吗? ...

  • 发布于 2021-03-22 02:17
  • 阅读 ( 227 )

您需要了解的7种浏览器cookies

...之前无法装满购物车,你会尝试在亚马逊购物。当你浏览网站时,你必须记住所有你想买的东西。 ...

  • 发布于 2021-03-22 09:29
  • 阅读 ( 212 )

Cookie并不都是坏的:在浏览器上启用Cookie的6个理由

...谈论网络上的cookies时,我们指的是HTTP cookies。HTTP cookie是网站放在计算机上的一个小文本文件。它通常包含三条信息:名称、值和一系列属性。 ...

  • 发布于 2021-03-23 13:01
  • 阅读 ( 287 )

5个私人网站在你不知情的情况下了解你

...似乎是一种无辜的行为,不是吗?你搜索谷歌,访问一些网站,阅读有趣的信息。你会惊讶地发现网站在你阅读时收集了大量关于你的信息吗? ...

  • 发布于 2021-03-24 23:38
  • 阅读 ( 236 )

如何使用浏览器的内置工具检查可疑链接

想想你一天访问了多少网站。现在想想你自己在浏览器中输入了多少网址。很可能,你访问的网站比你手动搜索的要多得多。我们大多数人都是通过链接来实现的。 ...

  • 发布于 2021-03-29 03:16
  • 阅读 ( 162 )
umq9l1
umq9l1

0 篇文章

相关推荐