简体   繁体   English

用户可以禁用 html5 sessionStorage 吗?

[英]Can user disable html5 sessionStorage?

can user disable the HTML5 sessionStorage just how he can disable cookies?用户可以禁用 HTML5 sessionStorage 吗?他如何禁用 cookie?

Also is sessionStorage will valid till page refresh? sessionStorage 在页面刷新之前是否有效? I mean what session actually mean, is it page refresh?我的意思是会话实际上是什么意思,是页面刷新吗?

Yes.是的。 HTML5 sessionStorage (and localStorage) can be disabled, and the data can also be cleared. HTML5 sessionStorage(和localStorage)可以禁用,也可以清除数据。

It is easy to prevent browsers from accepting localStorage and sessionStorage.很容易阻止浏览器接受 localStorage 和 sessionStorage。

  • In FireFox: Type “about:config” in your address bar and hit enter to view your internal browser settings.在 FireFox 中:在地址栏中键入“about:config”,然后按 Enter 键以查看内部浏览器设置。 Scroll down to „dom.storage.enabled“, right click on it and hit „Toggle“ to disable the DOM Storage.向下滚动到“dom.storage.enabled”,右键单击它并点击“Toggle”以禁用 DOM Storage。

  • In Internet Explorer: Select “Extras” -> “Internet Options” -> “Advanced” Tab -> Go to “Security” -> uncheck “Enable DOM-Storage”在 Internet Explorer 中:选择“附加”->“Internet 选项”->“高级”选项卡-> 转到“安全”-> 取消选中“启用 DOM 存储”

  • In Chrome: Open “Options” and select “Under the Hood” Tab.在 Chrome 中:打开“选项”并选择“引擎盖下”选项卡。 Click on “Content settings…”, select “Cookies” and set “Block sites from setting any data”.单击“内容设置...”,选择“Cookies”并设置“阻止站点设置任何数据”。

Also note: There are some browser security plugins/extras/add-ons that will prevent localStorage.另请注意:有一些浏览器安全插件/附加/附加组件会阻止 localStorage。 If localStorage / sessionStorage is vital to your page operation you should attempt a test read-write.如果 localStorage / sessionStorage 对您的页面操作至关重要,您应该尝试测试读写。

Regarding your other question: sessionStorage will survive a page refresh.关于您的另一个问题: sessionStorage在页面刷新后继续存在。 localStorage will persist between browsing sessions and survive a browser restart. localStorage 将在浏览会话之间持续存在,并在浏览器重启后继续存在。

can user disable the HTML5 sessionStorage just how he can disable cookies?用户可以禁用 HTML5 sessionStorage 吗?他如何禁用 cookie?

A User can either clear the cookies or Disallow any website from setting the cookie for themselves.Every browser has that option.用户可以清除 cookie 或禁止任何网站为自己设置 cookie。每个浏览器都有这个选项。

For Example-: Block Cookies例如-:阻止 Cookie

I mean what session actually mean, is it page refresh?我的意思是会话实际上是什么意思,是页面刷新吗?

First of all,its not a page refresh首先,它不是页面刷新

Most simple analogy :Session is a token which allows the user to visit any area of a web app.This token is valid untill the browser close.The moment you close the browser all the session data will get cleared.最简单的比喻:Session 是一个令牌,它允许用户访问 Web 应用程序的任何区域。此令牌在浏览器关闭之前一直有效。当您关闭浏览器时,所有会话数据都将被清除。

So what if i want my data to persist a little longer,Say i want permanently(considering that user have not cleared cookies) store some value on my users browser.那么,如果我希望我的数据保留更长时间,假设我希望永久(考虑到用户尚未清除 cookie)在我的用户浏览器上存储一些值。

LOCAL STORAGE :Local storage allows the data to persist beyond the browser close.So when the user comes back,we can use that data in our application.We can set the expiry for it.We can clear it when we want. LOCAL STORAGE :本地存储允许数据在浏览器关闭后仍然存在。因此当用户回来时,我们可以在我们的应用程序中使用该数据。我们可以为其设置到期时间。我们可以在需要时清除它。

NOTE :IE7 + support for SessionStorage and LocalStorage注意:IE7 + 支持 SessionStorage 和 LocalStorage

Conventional cookie storage :This is our good old way of storing some data on client.All browsers support it.But the problem is they provide too less space.传统的 cookie 存储:这是我们在客户端存储一些数据的旧方式。所有浏览器都支持它。但问题是它们提供的空间太少。

  • A cookie provides 4kb space and for every domain there is a limit of around 15-20 cookies.一个 cookie 提供 4kb 的空间,对于每个域,大约有 15-20 个 cookie 的限制。 LocalStorage and SessionStorage comes to our rescue.They provide quite good space. LocalStorage 和 SessionStorage 来拯救我们。它们提供了相当好的空间。 Different browsers have different capacity.不同的浏览器有不同的容量。

  • IE(10 mb)...Surprise surprise IE(10 mb)...惊喜惊喜

  • Mozzilla(5 mb) Mozzilla(5 mb)

  • Chrome(2.5 mb)铬(2.5 mb)

So,basically i can use localStorage if i want the data to persist beyond browser close and SessionStorage if i want the data to persist with in the browser close.所以,基本上我可以使用 localStorage 如果我希望数据在浏览器关闭后保留,如果我希望数据在浏览器关闭时保留 SessionStorage 。

There are some js availabe also..也有一些js可用..

  1. jStorage DOCUMENTATION j存储文档
  2. persist.js DOCUMENTATION persist.js文档

sessionStorage is used for session-based data. sessionStorage用于基于会话的数据。 It is erased when the tab is closed according to the standard.根据标准关闭选项卡时,它会被擦除。 You should use localStorage to persist across tab/window closings.您应该使用localStorage在选项卡/窗口关闭时保持不变。 Of course browsers can always not support these features or disable them, so you should handle that edge case to ensure your site remains functional.当然,浏览器始终无法支持或禁用这些功能,因此您应该处理这种边缘情况以确保您的网站保持正常运行。 The best way to do this is to revert back to using cookies or use a compatibility library like this one .最好的方法是恢复使用 cookie 或使用像这样的兼容性库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM