문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top