jQuery 用户可以禁用 html5 sessionStorage 吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17882647/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can user disable html5 sessionStorage?
提问by Seeker
can user disable the HTML5 sessionStorage just how he can disable cookies?
用户可以禁用 HTML5 sessionStorage 吗?他如何禁用 cookie?
Also is sessionStorage will valid till page refresh? I mean what session actually mean, is it page refresh?
sessionStorage 在页面刷新之前是否有效?我的意思是会话实际上是什么意思,是页面刷新吗?
采纳答案by HIRA THAKUR
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. LocalStorage and SessionStorage comes to our rescue.They provide quite good space. Different browsers have different capacity.
IE(10 mb)...Surprise surprise
Mozzilla(5 mb)
Chrome(2.5 mb)
一个 cookie 提供 4kb 的空间,对于每个域,大约有 15-20 个 cookie 的限制。LocalStorage 和 SessionStorage 来拯救我们。它们提供了相当好的空间。不同的浏览器有不同的容量。
IE(10 mb)...惊喜惊喜
Mozzilla(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可用..
- jStorage DOCUMENTATION
- persist.js DOCUMENTATION
回答by Bangkokian
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. Scroll down to ?dom.storage.enabled“, right click on it and hit ?Toggle“ to disable the DOM Storage.
In Internet Explorer:Select “Extras” -> “Internet Options” -> “Advanced” Tab -> Go to “Security” -> uncheck “Enable DOM-Storage”
In Chrome:Open “Options” and select “Under the Hood” Tab. Click on “Content settings…”, select “Cookies” and set “Block sites from setting any data”.
在 FireFox 中:在地址栏中键入“about:config”,然后按 Enter 键以查看内部浏览器设置。向下滚动到“dom.storage.enabled”,右键单击它并点击“Toggle”以禁用 DOM 存储。
在 Internet Explorer 中:选择“附加”->“Internet 选项”->“高级”选项卡-> 转到“安全”-> 取消选中“启用 DOM 存储”
在 Chrome 中:打开“选项”并选择“引擎盖下”选项卡。单击“内容设置...”,选择“Cookies”并设置“阻止站点设置任何数据”。
Also note: There are some browser security plugins/extras/add-ons that will prevent localStorage. If localStorage / sessionStorage is vital to your page operation you should attempt a test read-write.
另请注意:有一些浏览器安全插件/附加/附加组件会阻止 localStorage。如果 localStorage / sessionStorage 对您的页面操作至关重要,您应该尝试测试读写。
Regarding your other question: sessionStorage willsurvive a page refresh. localStorage will persist between browsing sessions and survive a browser restart.
关于您的另一个问题: sessionStorage将在页面刷新后继续存在。localStorage 将在浏览会话之间持续存在,并在浏览器重启后继续存在。
回答by Ditmar Wendt
sessionStorage
is used for session-based data. It is erased when the tab is closed according to the standard. You should use localStorage
to persist across tab/window closings. 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.
sessionStorage
用于基于会话的数据。根据标准关闭选项卡时,它会被擦除。您应该用于localStorage
在选项卡/窗口关闭时保持不变。当然,浏览器始终无法支持或禁用这些功能,因此您应该处理这种边缘情况以确保您的网站保持正常运行。最好的方法是恢复使用 cookie 或使用像这样的兼容性库。