Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
182
rated 0 times [  188] [ 6]  / answers: 1 / hits: 44605  / 14 Years ago, tue, august 10, 2010, 12:00:00

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>

More From » html

 Answers
106

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.


[#95967] Saturday, August 7, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
joseluispauld

Total Points: 13
Total Questions: 132
Total Answers: 98

Location: Venezuela
Member since Sat, Apr 24, 2021
3 Years ago
;