[英]HTML5 Local Storage Error
我正在嘗試檢查這是否是用戶第一次訪問我的應用程序。 因此,我檢查本地存儲中的count是否為null,如果為null,則該用戶為新用戶。 但是,下面的代碼在str_count = localStorage.getItem(“ count”);處停止。 此后將無行運行。 怎么了 如果用戶是新用戶,則本地存儲中將沒有“ count”,但是它應該只返回null而不崩潰。
var count = 0;
str_count = localStorage.getItem("count");
if (str_count == null || str_count == "null")
{
//do something
}
else
{
count = parseInt(str_count);
count++;
localStorage.setItem("count", count);
}
}
瀏覽器是否支持localStorage-您可以在嘗試獲取值之前檢查該功能:
var str_count = 0;
if (window.localStorage) {
str_count = localStorage.getItem('count');
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.