Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does IE8 out-of-the-box have support for 'localStorage'

I am trying to use the HTML5 feature localStorage. According to this blog it can be done using IE8, however when I try to use it I get a javascript error 'localStorage is null or not an object'

So my question: can localStorage be used by IE8 out-of-the-box? Here is my code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head>     <meta http-equiv="X-UA-Compatible" content="IE=8" />     <title>IE8 - DOM Storage</title>     <script type="text/javascript">          function Save() {             localStorage.setItem('key','value');                     }             </script> </head> <body>             <button onclick="Save();">         Save     </button>   </body> </html> 
like image 362
Spiderman Avatar asked Aug 10 '10 19:08

Spiderman


People also ask

Why we should not use localStorage?

Why Local Storage is Insecure and You Shouldn't Use it to Store Sensitive Data. Here's the deal: most of the bad things about local storage aren't all that important. You can still get away with using it but you'll just have a slightly slower app and minor developer annoyance.

Is localStorage available on all browsers?

Local Storage is "local" in that exact browser and ONLY in that browser. To retrieve something stored in Local Storage, you must use the same browser, the same key and retrieve it from a page in the same origin (e.g. domain).

Is localStorage supported?

localStorage browser support localStorage as a type of web storage is an HTML5 specification. It is supported by major browsers including IE8.

Does Internet Explorer support local storage?

IE also supports localStorage from IE8 but it does not support localStorage in IE7 and previous versions. Cookies are small text files stored by browsers allowing for a max of 4KB while with localStorage we can store Mbs of localStorage data.


1 Answers

It does support localStorage, though you need to be in IE8 mode (this will not work in IE7 mode).

To check that you're working in IE8 mode, load up the developer console. At the top, make sure that IE8 mode is selected. Standards mode would also be nice.

One thing that you also want to make sure of is that you're using the HTML5 doctype. You shouldn't be able to use an XHTML doctype with HTML5 features.

<!DOCTYPE html> 

Using this doctype should not impact your browser support.

Also, make sure you access window.localStorage. It shouldn't be an issue, but IE has been known to host weirder issues. Perhaps it's looking for a locally scoped localStorage object? Who knows.

like image 157
mattbasta Avatar answered Oct 09 '22 07:10

mattbasta