Question

if (localStorage)
{
    var menushown = JSON.parse(localStorage.getItem("menuState"));
    if (!menushown)
    {
        menushown = menuDefaultState;
    }
} 
else
{
    menushown = menuDefaultState;
}

The above JavaScript fails in Opera 10.10. It complains that localStorage is undefined on the second line. This is true, but because of the check on the first line it should never reach the second line, and not fail. What am I doing wrong?

Was it helpful?

Solution

Use if(window.localStorage), your current code will probably cause a warning or an error in non-compatible browsers.

localStorage is only available in Opera since 10.50, and at least for myself it works quite fine there with your code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top