1

I'm trying to use sessionStorage to display a modal alert only once per session - and I'm trying to do this in IE versions < 9.

The alert will tell users how terrible their IE version < 9 is, and to please upgrade.

Using sessionStorage works fine in IE 11. But in older versions of IE, I can't get it to take effect (sessionStorage comes back as 'undefined or null'). I've tested this locally and on a live site. Does sessionStorage even work in IE < 9, and if not, what's a good alternative I can use in these older IE versions to only display this alert once per 'session'?

My code looks like:

if (sessionStorage.getItem('browserCheck') !== 'true') {
     // define alert function
     // call alert function
    sessionStorage.setItem('browserCheck','true');
}
Kyle Vassella
  • 2,296
  • 10
  • 32
  • 62
  • Just check to see if `sessionStorage` is defined at all. – Pointy Dec 13 '17 at 00:01
  • It's not (comes back as 'undefined or null' in the dev tools) - do you know a good alternative? – Kyle Vassella Dec 13 '17 at 00:09
  • Possible duplicate of [session storage not working in IE](https://stackoverflow.com/questions/16212347/session-storage-not-working-in-ie) but also https://stackoverflow.com/questions/10916210/html5-code-not-working-in-ie9 – Rob Dec 13 '17 at 00:09
  • @Rob that question/answer does not address my issue, since I'm testing it on a live site - not just locally. – Kyle Vassella Dec 13 '17 at 00:33
  • 1
    Use a storage library that provides cookie fallback like https://github.com/marcuswestin/store.js/ – charlietfl Dec 13 '17 at 00:58

1 Answers1

0

So apparently, sessionStorage is valid in IE 7 and 8. I was just deleting my cache wrong in the browser before switching the dev tools emulator from IE11 to IE 7 or 8. I was able to fix this by unchecking the top box inside of the 'delete history' prompt in IE: enter image description here

Earlier, sessionStorage was coming back as 'undefined or null' in IE 7 and 8 in my dev tools console - but I think this was a because of a separate issue. It isn't undefined - it works.

I believe localStorage actually is invalid in IE < 8 though - so if localStorage is your problem, this link is helpful: HTML5 Local Storage fallback solutions

Kyle Vassella
  • 2,296
  • 10
  • 32
  • 62