简体   繁体   中英

Can user disable html5 sessionStorage?

can user disable the HTML5 sessionStorage just how he can disable cookies?

Also is sessionStorage will valid till page refresh? 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.

It is easy to prevent browsers from accepting localStorage and 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”.

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.

Regarding your other question: sessionStorage will survive a page refresh. localStorage will persist between browsing sessions and survive a browser restart.

can user disable the HTML5 sessionStorage just how he can disable cookies?

A User can either clear the cookies or Disallow any website from setting the cookie for themselves.Every browser has that option.

For Example-: Block Cookies

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.

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.

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.

NOTE :IE7 + support for SessionStorage and 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.

  • 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)

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.

There are some js availabe also..

  1. jStorage DOCUMENTATION
  2. persist.js DOCUMENTATION

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 .

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