Page 1 of 1

Set Default Values for Local Storage Variables

Posted: Fri Jan 09, 2015 1:50 am
by KorryRogers

I used to be able to do this in the old editor, but I'm having problems in the new one. I'm trying to setup some local storage variable default values when the app launches. Here's the code I've tested and none of it works. I've even tried putting it in a setTimeout() function to no avail.

if(!localStorage.onlineStatus localStorage.onlineStatus === null localStorage.onlineStatus = '') {
localStorage.onlineStatus = '0'
}

What am I doing wrong? How can I setup a default value? TIA


Set Default Values for Local Storage Variables

Posted: Fri Jan 09, 2015 1:52 am
by KorryRogers

Also, I'm running this on the page show event of the launch page.


Set Default Values for Local Storage Variables

Posted: Fri Jan 09, 2015 8:53 am
by Ihor Didevych

Hi Korry,

Your approach is correct.
Could you clarify, how do you test your LSV ?


Set Default Values for Local Storage Variables

Posted: Fri Jan 09, 2015 12:21 pm
by KorryRogers

I'm just looking at the local storage variables directly in the dev tools in Chrome. They don't get created.


Set Default Values for Local Storage Variables

Posted: Mon Jan 12, 2015 3:03 am
by Yurii Orishchuk

Hi Korry,

Here is a correct code:

precode

var currentValue = localStorage.getItem("onlineStatus");

if(!currentValue currentValue === null currentValue = '') {
//Replace this value with your goal default value.
var defaultValue = "0&quot
localStorage.setItem("onlineStatus", defaultValue);
}

/code/pre

More details here: http://www.w3schools.com/html/html5_w...

Regards